🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Topological Sort: all 15 questions

Quiz: Topological Sort · Question 15 of 15

You need the topological order that is smallest in dictionary order. What do you change in Kahn's algorithm?

You need the topological order that is smallest in dictionary order. What do you change in Kahn's algorithm?

  1. A.Use a stack instead of the queue
  2. B.Sort the edges first
  3. C.Run DFS instead
  4. D.Replace the queue with a min-heap, so the smallest ready node is always taken next
Answer & explanation

Correct answer: Replace the queue with a min-heap, so the smallest ready node is always taken next

Among all nodes with in-degree 0, the heap gives the smallest one each time.

Can you get the rest right without peeking?

Take the timed Quiz: Topological Sort quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →