New paste Repaste Download
# Sample graph represented as an adjacency list
#dictionary
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
visited = set()
def dfs(graph, vertex):
  visited.add(vertex)
  print(vertex)
  for neighbor in graph[vertex]:
    if neighbor not in visited:
      dfs(graph, neighbor)
# Starting DFS from vertex 'A'
dfs(graph, 'A')
Filename: None. Size: 393b. View raw, , hex, or download this file.

This paste expires on 2025-05-13 04:32:10.454487. Pasted through web.