Quiz: Dijkstra’s Algorithm
1. What is Dijkstra's algorithm used for?
a) Sorting numbers
b) Finding the shortest path in a graph
c) Generating random numbers
d) Solving linear equations
Answer: b) Finding the shortest path in a graph
2. What type of graphs can Dijkstra's algorithm be applied to?
a) Only undirected graphs
b) Only weighted graphs with non-negative weights
c) Any graph with negative weights
d) Graphs with self-loops
Answer: b) Only weighted graphs with non-negative weights
3. What data structure is commonly used in Dijkstra's algorithm to find the next
closest vertex?
a) Stack
b) Queue
c) Priority Queue (or Min-Heap)
d) Linked List
Answer: c) Priority Queue (or Min-Heap)
4. What determines the order in which vertices are processed in Dijkstra’s algorithm?
a) The vertex with the smallest distance from the source is processed first.
b) Vertices are processed in alphabetical order.
c) The vertex with the largest distance from the source is processed first.
d) Vertices are processed in a random order.
Answer: a) The vertex with the smallest distance from the source is processed first.
5. In Dijkstra's algorithm, what is initialized to infinity (\( \infty \)) at the start?
a) The distance of all nodes from the source
b) The weights of the edges
c) The adjacency list
d) The source node distance
Answer: a) The distance of all nodes from the source
6. What is the first step in Dijkstra’s algorithm?
a) Update all node distances to the source
b) Add all vertices to the priority queue
c) Initialize the source distance to 0
d) Traverse all edges in the graph
Answer: c) Initialize the source distance to 0
7. Dijkstra's algorithm will not work correctly if the graph contains:
a) Positive edge weights
b) Zero-weight edges
c) Negative edge weights
d) Cycles
Answer: c) Negative edge weights
8. Why does Dijkstra’s algorithm guarantee the shortest path?
a) It explores nodes in increasing order of their distance from the source.
b) It explores all possible paths in the graph.
c) It always uses a breadth-first search approach.
d) It revisits each node multiple times.
Answer: a) It explores nodes in increasing order of their distance from the source.
9. What happens to a vertex once it is "visited" in Dijkstra’s algorithm?
a) Its shortest path is finalized and will not change.
b) It is removed from the graph.
c) It is added back into the priority queue.
d) Its distance is reset to infinity.
Answer: a) Its shortest path is finalized and will not change.
10. What is the primary limitation of Dijkstra’s algorithm?
a) It does not work with graphs containing negative weight edges.
b) It is too slow for small graphs.
c) It cannot handle graphs with cycles.
d) It works only for unweighted graphs.
Answer: a) It does not work with graphs containing negative weight edges.
11. Why is Dijkstra’s algorithm slow for large graphs?
a) It cannot process many edges
b) It has high time complexity
c) It skips vertices
d) It uses random paths
Answer: b) It has high time complexity
12. What type of application commonly uses Dijkstra’s algorithm?
a) GPS and navigation systems
b) Sorting algorithms
c) Social media apps
d) Image recognition systems
Answer: a) GPS and navigation systems
13. How does Dijkstra’s algorithm choose the next node to process?
a) Randomly
b) By smallest distance from the source
c) By largest distance from the source
d) By alphabetical order
Answer: b) By smallest distance from the source
14. What happens if a graph has disconnected components when using Dijkstra’s
algorithm?
a) It finds a path anyway
b) It processes only connected components
c) It outputs an error
d) It stops immediately
Answer: b) It processes only connected components
15. What happens when Dijkstra’s algorithm encounters a node with a smaller path
than previously found?
a) It updates the node’s distance
b) It stops processing
c) It deletes the node from the graph
d) It ignores the node
Answer: a) It updates the node’s distance
16. What is an optimal data structure for Dijkstra’s algorithm when using a priority
queue?
a) Array
b) Binary heap
c) Stack
d) Queue
Answer: b) Binary heap
17. Who developed the Dijkstra’s Algorithm
a) Edsger W. Dijkstra
b) Arthur N. Dijkstra
c) Dijkstra Armstrong
d) Adolf Dijkstra
Answer: a) Edsger W. Dijkstra
18. What year did the Dijkstra’s algorithm developed
a) 1965
b) 1956
c) 1966
d) 1966
Answer: b) 1956
19. Dijkstra’s algorithm is a computer science algorithm that finds the shortest path
between ______ in a weighted graph.
a) lines
b) curves
c) nodes
d) circles
Answer: c) nodes
20. What application uses the Dijkstra’s Algorithm
a) Google Maps
b) Canva
c) Telegram
d) Tiktok
Answer: a)Google Maps