🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Topological Sort: questions with answers

15 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. A topological order of a directed graph exists if and only if the graph:
  2. Q2. In Kahn's algorithm, which nodes go into the queue at the start?
  3. Q3. What does this print? (code)
  4. Q4. Kahn's algorithm finishes with 4 nodes in the order, but the graph has 6 nodes. What does this mean?
  5. Q5. In the course problem, the pair [a, b] means "to take course a, first take course b". Which edge do you add?
  6. Q6. In DFS-based cycle detection with three colours, a cycle is found when DFS reaches a node that is:
  7. Q7. In the DFS method, the topological order is:
  8. Q8. What is the time complexity of topological sort for V nodes and E edges?
  9. Q9. What does this print? (code)
  10. Q10. Why is the longest path easy to find in a DAG but hard in a general graph?
  11. Q11. What does this print? (code)
  12. Q12. What is the in-degree of a node?
  13. Q13. What does this print? (code)
  14. Q14. Can a directed graph have more than one valid topological order?
  15. Q15. You need the topological order that is smallest in dictionary order. What do you change in Kahn's algorithm?