Search This Blog

Wednesday, September 9, 2020

Bit Stuffing in Computer Network Using Python

Bit Stuffing Mechanism


Here, the delimiting flag sequence generally contains six or more consecutive 1s. Most protocols use the 8-bit pattern 01111110 as flag. In order to differentiate the message from the flag in case of same sequence, a single bit is stuffed in the message. Whenever a 0 bit is followed by five consecutive 1bits in the message, an extra 0 bit is stuffed at the end of the five 1s. When the receiver receives the message, it removes the stuffed 0s after each sequence of five 1s. The un-stuffed message is then sent to the upper layers.




 


Code :

Byte Stuffing in Computer Network Using Python

Byte Stuffing Mechanism


If the pattern of the flag byte is present in the message byte sequence, there should be a strategy so that the receiver does not consider the pattern as the end of the frame. Here, a special byte called the escape character (ESC) is stuffed before every byte in the message with the same pattern as the flag byte. If the ESC sequence is found in the message byte, then another ESC byte is stuffed before it.




Code :

Monday, July 6, 2020

The Flight Plan - Hackerearth Problem Solution Using Python


Here , To solve this problem we have use the BFS algorithm using python in which we just add a "dist" list in which we store distance of every node from its parent node. And we have use dictionary named "dd" in which we store its parent node if we print that dictionary we get the path for for each node from source given node.
For the Problem goto below link and search for problem: The Flight Plan

Code :

Social Networking Graph - Hackerearth Problem Solution Using Python


Here , To solve this problem we have use the BFS algorithm using python in which we just add a "dist" list in which we store distance of every node from its parent node. And then we see count nodes which are at a given distance from given source node.
For the Problem goto below link and search for problem: Social Networking Graph

Code :

Sunday, July 5, 2020

Monk and the Islands - Hackerearth Problem Solution Using Python


Here , To solve this problem we have use the BFS algorithm using python in which we just add a "dist" list in which we store distance of every node from its parent node.
For the Problem goto below link and search for problem: Monk and Islands

Code :

Shortest Path Using Breadth First Search (BFS)

Shortest Path Using Breadth First Search (BFS)


Here , To find the shortest path using BFS first we have to know that the graph should always be unweighted graph .
If you know about the BFS algorithm then to find shortest path we have to add only one thing that is a dictionary named "dist" which records the distance of every node from given node As shown in below code.




Code :

Alien Dictionary

code:   from collections import defaultdict class Solution:     def __init__(self):         self.graph=defaultdict(list)                  ...