Compute the breadth-first search forest of a graph, such that adjacent vertices are explored in increasing order according to their Ord instance. The search is seeded by a list of vertices that will become the roots of the resulting forest. Duplicates in the list will have their first occurrence explored and subsequent ones ignored. The seed vertices that do not belong to the graph are also ignored.
Complexity: O((L + m) * log n) time and O(n) space, where L is the number of seed vertices.
forest $ bfsForest (edge 1 2) [0] == empty
forest $ bfsForest (edge 1 2) [1] == edge 1 2
forest $ bfsForest (edge 1 2) [2] == vertex 2
forest $ bfsForest (edge 1 2) [0,1,2] == vertices [1,2]
forest $ bfsForest (edge 1 2) [2,1,0] == vertices [1,2]
forest $ bfsForest (edge 1 1) [1] == vertex 1
isSubgraphOf (forest $ bfsForest x vs) x == True
bfsForest x (vertexList x) == map (\v -> Node v []) (nub $ vertexList x)
bfsForest x [] == []
bfsForest empty vs == []
bfsForest (3 * (1 + 4) * (1 + 5)) [1,4] == [ Node { rootLabel = 1
, subForest = [ Node { rootLabel = 5
, subForest = [] }]}
, Node { rootLabel = 4
, subForest = [] }]
forest $ bfsForest (circuit [1..5] + circuit [5,4..1]) [3] == path [3,2,1] + path [3,4,5]