data-structures Breadth First Search


Example

Algorithm BFS(G)

Input graph G

Output labeling of the edges and partition of the vertices of G

    for all u ∈ G.vertices()
        setLabel(u, UNEXPLORED)
    for all e ∈ G.edges()
    setLabel
    (e, UNEXPLORED)
    for all v ∈ G.vertices()
        if getLabel(v) = UNEXPLORED
            BFS(G, v)

Demonstration

Demo continued

Demo continued