Created
August 2, 2021 17:18
-
-
Save GEEGABYTE1/fac42ec52d89784fbc6d8d0cfc63c288 to your computer and use it in GitHub Desktop.
Depth-First and BFS traversal
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
## Our graph has been converted into a dictionary in the form of {vertex: [edge1, edge2, edge3, ..., edge n]} ## | |
### BFS Traversal ### | |
first_element = list(test_graph.graph_dict.keys())[0] | |
last_element = list(test_graph.graph_dict.keys())[-1] | |
lst = list(test_graph.graph_dict[first_element].edges.keys()) | |
for i in range(len(lst)): | |
first_edge = lst[0] | |
if i == 0: | |
pass | |
else: | |
dictionary[first_element].pop(0) | |
lst.pop(0) | |
output = bfs(dictionary, first_element, last_element) | |
######################### | |
### DFS Traversal ### | |
first_element = list(test_graph.graph_dict.keys())[0] | |
lst = list(test_graph.graph_dict[first_element].edges.keys()) | |
for i in range(len(lst)): | |
first_edge = lst[0] | |
if i == 0: | |
pass | |
else: | |
dictionary[first_element].pop(0) | |
lst.pop(0) | |
output = dfs(dictionary, first_element) | |
print() | |
######################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment