Dijkstra's algorithm finds the shortest path from a starting point to all other points in a graph with non-negative edge weights.
Click to reveal answer
beginner
What type of graphs can Dijkstra's algorithm be applied to?
It works on graphs with non-negative edge weights, whether directed or undirected.
Click to reveal answer
intermediate
How does Dijkstra's algorithm decide which node to visit next?
It always picks the unvisited node with the smallest known distance from the start.
Click to reveal answer
intermediate
What data structure is commonly used to efficiently select the next node in Dijkstra's algorithm?
A priority queue (or min-heap) is used to quickly find the node with the smallest distance.
Click to reveal answer
advanced
Why can't Dijkstra's algorithm handle graphs with negative edge weights?
Because it assumes once a node's shortest distance is found, it won't get shorter. Negative edges can break this assumption.
Click to reveal answer
What does Dijkstra's algorithm compute?
ADetect cycles in a graph
BMinimum spanning tree
CMaximum flow in a network
DShortest paths from one node to all others
✗ Incorrect
Dijkstra's algorithm finds the shortest paths from a single starting node to all other nodes.
Which data structure helps Dijkstra's algorithm pick the next node efficiently?
AStack
BQueue
CPriority queue
DLinked list
✗ Incorrect
A priority queue allows quick access to the node with the smallest current distance.
Dijkstra's algorithm cannot be used if the graph has:
ANegative edge weights
BMultiple nodes
CDirected edges
DLoops
✗ Incorrect
Negative edge weights can cause incorrect shortest path calculations in Dijkstra's algorithm.
What is the initial distance assigned to the starting node in Dijkstra's algorithm?
AInfinity
BZero
COne
DUndefined
✗ Incorrect
The starting node's distance to itself is zero.
When does Dijkstra's algorithm stop?
AWhen all nodes have been visited
BAfter visiting half the nodes
CWhen the shortest path to one node is found
DAfter a fixed number of steps
✗ Incorrect
The algorithm finishes when it has found the shortest paths to all nodes.
Explain how Dijkstra's algorithm finds the shortest path in a graph.
Think about how the algorithm updates distances and chooses nodes step by step.
You got /5 concepts.
Describe why Dijkstra's algorithm does not work with negative edge weights.
Consider what happens if a path gets shorter after a node is processed.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of Dijkstra's algorithm in graph theory?
easy
A. To detect cycles in a graph
B. To sort nodes in alphabetical order
C. To find the maximum flow in a network
D. To find the shortest path from one node to all other nodes in a weighted graph
Solution
Step 1: Understand the goal of Dijkstra's algorithm
Dijkstra's algorithm is designed to find the shortest distances from a starting node to all other nodes in a graph where edges have weights.
Step 2: Compare with other graph algorithms
Sorting nodes or detecting cycles are different tasks handled by other algorithms, not Dijkstra's.
Final Answer:
To find the shortest path from one node to all other nodes in a weighted graph -> Option D
Quick Check:
Shortest path finding = To find the shortest path from one node to all other nodes in a weighted graph [OK]
Hint: Remember: Dijkstra finds shortest paths from one node [OK]
Common Mistakes:
Confusing shortest path with sorting or cycle detection
Thinking it finds maximum flow
Assuming it works on unweighted graphs only
2. Which of the following is the correct step in Dijkstra's algorithm?
easy
A. Select the unvisited node with the smallest tentative distance
B. Select the visited node with the largest distance
C. Update distances by adding the maximum edge weight
D. Remove nodes with the highest degree first
Solution
Step 1: Identify the selection criteria in Dijkstra's algorithm
The algorithm always picks the unvisited node with the smallest tentative distance to explore next.
Step 2: Eliminate incorrect options
Choosing visited nodes or using maximum edge weights contradicts the algorithm's logic.
Final Answer:
Select the unvisited node with the smallest tentative distance -> Option A
Quick Check:
Pick closest unvisited node = Select the unvisited node with the smallest tentative distance [OK]
Hint: Always pick closest unvisited node next [OK]
Common Mistakes:
Picking visited nodes again
Adding maximum instead of minimum edge weights
Removing nodes based on degree
3. Consider the graph with nodes A, B, C and edges: A-B (4), A-C (2), C-B (1). Starting from A, what is the shortest distance to B using Dijkstra's algorithm?
medium
A. 3
B. 4
C. 2
D. 1
Solution
Step 1: Initialize distances from A
Distance to A is 0, to B is infinity, to C is infinity initially.
Step 2: Update distances via neighbors
From A, distance to C is 2, to B is 4. Next, from C, distance to B is 2 + 1 = 3, which is less than 4, so update B's distance to 3.
Final Answer:
3 -> Option A
Quick Check:
Shortest path A->C->B = 3 [OK]
Hint: Check all paths, pick minimum sum of edges [OK]
Common Mistakes:
Ignoring the path through C
Choosing direct edge without comparison
Mixing up edge weights
4. In the following pseudocode for Dijkstra's algorithm, what is the error?
1. Initialize distances to infinity
2. Set distance to start node as 0
3. While unvisited nodes remain:
4. Pick any unvisited node
5. Update distances to neighbors
6. Mark node as visited
medium
A. Not initializing distances to zero
B. Picking any unvisited node instead of the one with smallest distance
C. Marking nodes as visited before updating distances
D. Setting start node distance to infinity
Solution
Step 1: Identify the node selection step
The algorithm must pick the unvisited node with the smallest tentative distance, not just any node.
Step 2: Understand the impact of wrong selection
Picking any node can lead to incorrect shortest paths because it ignores the priority of closer nodes.
Final Answer:
Picking any unvisited node instead of the one with smallest distance -> Option B
Quick Check:
Must pick closest unvisited node [OK]
Hint: Always pick node with smallest tentative distance [OK]
Common Mistakes:
Choosing nodes randomly
Setting wrong initial distances
Marking nodes visited too early
5. You have a weighted graph with some edges having zero weight. How does Dijkstra's algorithm handle zero-weight edges when finding shortest paths?
hard
A. It treats zero-weight edges as infinite weight edges
B. It ignores zero-weight edges completely
C. It treats zero-weight edges like any other edge and updates distances accordingly
D. It causes the algorithm to fail or loop infinitely
Solution
Step 1: Understand edge weights in Dijkstra's algorithm
Dijkstra's algorithm works with non-negative weights, including zero, treating them as valid edges.
Step 2: Effect of zero-weight edges
Zero-weight edges allow the algorithm to update distances without adding cost, effectively moving to connected nodes at no extra distance.
Final Answer:
It treats zero-weight edges like any other edge and updates distances accordingly -> Option C
Quick Check:
Zero weight edges are valid and processed [OK]
Hint: Zero weight edges count as normal edges with no added cost [OK]
Common Mistakes:
Ignoring zero-weight edges thinking they cause errors
Assuming zero weight means infinite cost
Believing algorithm loops infinitely with zero weights
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.