Algorithms and Data Structures · Middle · Question 59 of 75

Which data structure makes Dijkstra's algorithm efficient?

Explanation

The heap gives the closest unvisited vertex in O(log V). With a plain queue the algorithm becomes BFS, which ignores weights; scanning all vertices for the minimum makes it O(V²).

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 59

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz