Q. In Dijkstra's algorithm, what is the purpose of the 'visited' set?
A.
To store all vertices
B.
To keep track of the shortest path
C.
To avoid processing the same vertex multiple times
D.
To store the distances from the source
Solution
The 'visited' set is used to keep track of the vertices that have already been processed to avoid processing the same vertex multiple times, ensuring efficiency.
Correct Answer:
C
— To avoid processing the same vertex multiple times
Q. What is the primary difference between Dijkstra's algorithm and the A* search algorithm?
A.
A* uses heuristics, Dijkstra's does not
B.
Dijkstra's is faster than A*
C.
A* can only be used on trees
D.
Dijkstra's algorithm is recursive
Solution
The primary difference is that A* uses heuristics to guide its search, while Dijkstra's algorithm does not use any heuristics and explores all paths equally.
Correct Answer:
A
— A* uses heuristics, Dijkstra's does not