Answers for "dfs and bfs inn python"

0

dfs and bfs inn python

def dfs(graph, start):
    visited, stack = set(), [start]
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex] - visited)
    return visited

dfs(graph, 'A') # {'E', 'D', 'F', 'A', 'C', 'B'}
Posted by: Guest on August-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language