title: Algorithm for BFS traveral of an acylic directed graph
body: <p>I'm looking for an elegant Python program that does a BFS traveral of a DAG:</p>
  
  <p>Node A is connected to B (<code>A-&gt;B</code>) if A "depends on" B (think of python package Foo "depending upon" Bar: Foo->Bar). </p>
  
  <p>In a graph of about 7000 such nodes, I want to sort all nodes such that for all possible <code>(i, j)</code> where <code>1&gt;=i&lt;j&lt;=7000</code> .. <code>depends(Ni, Nj)</code> is False. depends(A, B) = True if and only if <code>A-&gt;B</code> or A "depends on" B .. and <code>Nx</code> is the node occuring in <code>x</code>th position in the sorted list.</p>
  
  <p>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. </p>