1dfs
1dfs
ipynb - Colab
#DFS (Depth-First Search) is a graph traversal algorithm that explores the vertices of a graph in a depthward motion, going as far as pos
class Graph:
if __name__ == '__main__':
edges = [
(1, 2), (1, 7), (1, 8), (2, 3), (2, 6), (3, 4),
(3, 5), (8, 9), (8, 12), (9, 10), (9, 11)
]
n = 13
for i in range(n):
if not discovered[i]: # If a vertex is not discovered yet
DFS(graph, i, discovered) # Call DFS starting from that vertex
0 1 2 3 4 5 6 7 8 9 10 11 12
https://colab.research.google.com/drive/1W-DZ62YB833v0ir3yGsDotEpdHNZf5Ug#scrollTo=txJygyiIdDwo&printMode=true 1/1