dfspan←{                    ⍝ Depth-first spanning tree: graph ⍺ from vertex ⍵.
    graph←⍺                 ⍝ ⍺ is graph vector.
    trav{                  ⍝ initial vertex and parent
        ¯2≠⍺⊃⍵:⍵            ⍝ vertex visited: backtrack
        next←⌽⍺⊃graph       ⍝ edges from vertex ⍺
        tree←⍺⍺@⍺⊢⍵         ⍝ ⍺⍺ is ⍺'s parent
        ⊃⍺ ∇∇/next,⊂tree    ⍝ visiting each edge in order
    }                       ⍝ :: tree ← vtx (vtx ∇∇) tree
    ⍵(¯1 trav)¯2⊣¨⍺         ⍝ depth-first traversal of graph ⍵
}

code_colours

test script

Back to: notes

Back to: Workspaces