⍝ Breadth-first search of graph ⍺:

    ⎕io←1

    a←(2 3)(3)(2 4)(1 5)(3)     ⍝ graph "a"
    a
┌───┬─┬───┬───┬─┐
│2 3│3│2 4│1 5│3│
└───┴─┴───┴───┴─┘

    a search 3              ⍝ vertices in a breadth-first search from vertex 3
3 2 4 1 5

    {a search ⍵}¨⍳⍴a ⍝ search from each vertex.
┌─────────┬─────────┬─────────┬─────────┬─────────┐
│1 2 3 4 5│2 3 4 1 5│3 2 4 1 5│4 1 5 2 3│5 3 2 4 1│
└─────────┴─────────┴─────────┴─────────┴─────────┘

Back to: code

Back to: Workspaces