Medium · O((V + E) log V)
Dijkstra'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
A directed graph with 6 vertices and these edges (from → to, weight): 0→1 (7), 0→2 (2), 2→1 (3), 1→3 (1), 2→3 (8), 3→4 (2), 2→4 (9). Vertex 5 has no edges. After dijkstra(graph, 0), what is dist[4] and which path does shortestPath give for target 4?
In graph[0] the edges are listed in this order: 0→3 (2), 0→1 (2), 0→2 (2). The source is popped and its three neighbours go into the queue, all at distance 2. Which vertex is popped next?
A graph with edges, in this order: 0→2 (1), 0→1 (1), 2→3 (1), 1→3 (1). Two shortest paths of length 2 reach vertex 3. What does shortestPath(prev, 0, 3) return?
On the graph from the first question (0→1 (7), 0→2 (2), 2→1 (3), 1→3 (1), 2→3 (8), 3→4 (2), 2→4 (9)), how many popped entries are thrown away by if (distance > dist[u]) continue?
A graph with 3 vertices and the edges 0→1 (5) and 2→0 (1). After dijkstra(graph, 0), what are dist[2], prev[2] and shortestPath(prev, 0, 2)?
Edges 0→1 (2), 0→2 (3) and 2→1 (−2): a negative weight, which Dijkstra's proof doesn't allow. What does this listing return for dist[1]?
Edges 0→1 (1), 1→2 (−1) and 2→1 (0). The cycle 1 → 2 → 1 has total weight −1. What does dijkstra(graph, 0) do?
Edges 0→1 (9), 0→1 (2) (a parallel edge), 1→1 (0) (a self-loop) and 1→2 (0). What does dijkstra(graph, 0) return?
A dense graph has V vertices and about V² edges. How long does this heap-based Dijkstra take?
Pairs [distance, vertex] are pushed into the min-heap in this order: [3, 0], [8, 1], [5, 2], [9, 3], [7, 4], [6, 5]. Then pop() returns [3, 0]. What does the heap's array look like afterwards?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10
Take it further
- AnimationPathfinding
Pathfinding Maze
An editable neon maze where BFS, Dijkstra, A* and greedy search race to the goal, step by step
Free
