I'm looking for an elegant Python program that does a BFS traveral of a DAG:
Node A is connected to B (A->B
) if A "depends on" B (think of python package Foo "depending upon" Bar: Foo->Bar).
In a graph of about 7000 such nodes, I want to sort all nodes such that for all possible (i, j)
where 1>=i<j<=7000
.. depends(Ni, Nj)
is False. depends(A, B) = True if and only if A->B
or A "depends on" B .. and Nx
is the node occuring in x
th position in the sorted list.
Note: A node can have multiple parents. Eg: A->C and B->C. Therefore, according to the above sorting rule, A and B must come before C.