lintcode-615

description : lintcode 615

topology sorting

dag (directed acyclic graph) => G = ( V, E )

  • linear ordering
  • no cycle

topology sort (G)

  1. store neighbor in dictionary edge
  2. compute indegree
  3. find node where indegree == 0 & add to queue
  4. use bfs ( add 1 to count visited node, and decrease indegree by 1 )
  5. if indegree of beighbor node reduce to 0 add into queue

solution : 615 solution

G = (V, E)
time analysis: O (V+E)

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×