Medium · O(V + E)
Topological Sort (Kahn's Algorithm) quiz
Answer the questions in your own time, change a pick whenever you like, then hand in to see your score and why each answer is right. Nothing is saved or sent.
Questions (10)
- Viewing
- Answered
- Not answered
Six tasks, numbered 0 to 5, with the edges (from → to) 5→0, 5→2, 4→0, 4→1, 2→3 and 3→1. What does topologicalSort(graph) return?
For the same graph, what does the inDegree array hold right after the counting loop, before anything is queued?
A diamond: 4 vertices, and the edges are listed in this order: 0→2, 0→1, 2→3, 1→3. What does topologicalSort return?
5 vertices and the edges 3→0, 4→1 and 4→2. What does topologicalSort return?
The edges 0→1, 1→2, 2→1 and 2→3 on 4 vertices. What happens, and which vertices still have a non-zero in-degree when the loop ends?
3 vertices and the edges 0→1 and 1→1 (a self-loop). What does topologicalSort return?
3 vertices and the edges 0→1, 0→1 (repeated), 1→2 and 0→2. What are the initial in-degrees, and what does topologicalSort return?
On the 6-vertex, 6-edge graph from the first question, how many times does inDegree[v]-- run in total?
How many different valid topological orders does the 6-vertex graph from the first question have? (Every ordering of the 6 vertices was tried, 720 in all.)
Run the DFS version on the same graph: start from 0, 1, 2, … in turn, append each vertex when it finishes (after its descendants) and reverse the list at the end. What comes out?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10
Take it further
- AnimationGraphs
Topological Sort Animation
A glowing dependency graph that peels itself in order: Kahn's algorithm with live in-degree badges, a visible FIFO queue and the order filling up
Free
