Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

breadth first search graph python

def bfs(node):
    """ graph breadth-first search - iterative """
    from collections import deque
    
    q = deque()
    q.append(node)
    node.visited = True
    
    while q:
        current = d.popleft()
        print(current)  
            
        for node in current.adjList:
            if not node.visited: 
                q.append(node)
                node.visited = True
 
PREVIOUS NEXT
Tagged: #breadth #search #graph #python
ADD COMMENT
Topic
Name
1+8 =