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