Last active
May 30, 2022 03:18
-
-
Save jiachen247/5f137fa3ed18e1300be45b68095420ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
graph = { | |
'a' : ['b','c'], | |
'b' : ['d'], | |
'c' : ['e'], | |
'd' : ['f'], | |
'e' : [], | |
'f' : [] | |
} | |
visited = set() # List to keep track of visited nodes. | |
queue = [] #Initialize a queue | |
def bfs(node): | |
visited.add(node) | |
queue.append(node) | |
while queue: | |
s = queue.pop(0) | |
print (s, end = " ") | |
for neighbour in graph[s]: | |
if neighbour not in visited: | |
visited.add(node) | |
queue.append(neighbour) | |
# Driver Code | |
bfs('a') | |
def containsX(node, target): | |
pass | |
print(containsX('a', 'e')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment