span←{                          ⍝ Breadth-first spanning tree for graph ⍺.
    graph←⍺                     ⍝ ⍺ is graph vector.
    (¯2+(⍳⍴⍺)∊⍵){               ⍝ ⍺: partial spanning tree.
        ⍵≡⍬:⍺                   ⍝ no vertices: done.
        nextgraph[⍵]∩¨⊂⍸⍺=¯2   ⍝ untravelled edges
        back←⍵+0×next           ⍝ back link per edge
        tree(back)@(next)⊢⍺  ⍝ partial spanning tree
        tree ∇∪∊next            ⍝ advanced wave front
    }⍵                          ⍝ ⍵: next wave of vertices to visit.
}

code_colours

test script

Back to: notes

Back to: Workspaces