It is always important to look back and seek improvement of yourself. I am the person who love to record my baby steps. It is been ten days since I updated my blog. Before I jumped into my technical memory. I need to confess that I had a crunsh on somebody and I am trying to be forward. IT IS SUPER HARD FOR ME TO MAKE THE FIRST MOVE. Sometimes I am confused if you are interested in me or not. Anyway, before jumping into network stuff, lets solve two coding questions. Breadth First Search
class Graph:
# Constructor
def __init__(self):
# default dictionary to store graph
self.graph = dict(list)
# function to add an edge to the graph
def addEdge(self, u, v):
self.graph[u].append(v)
#Function to print BFS of a graph
def BFS(self, s):
#Mark all the vertices as not visited
visited = [False] * (len(self.graph))
# Mark the source node as visited and enqueue it
queue.append(s)
visited[s] = True
while queue:
# Dequeue a vertex from queue and print it
s = queue.pop(0)
print(s, end = " ")
# Get all the adjacent vertices of the dequeued vertex s.
# If a adjacent has not been visited, then mark it as
# visited and enqueue it.
for i in self.graph[s]:
if visited[i] == False:
queue.append(i)
visited[i] = True
Implement queue using two stacks This