wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

To implement Dijkstra's shortest path algorithm on unweighted graphs so that it runs in linear time, then data structure to be used is

A
Heap
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
B-Tree
No worries! Weā€˜ve got your back. Try BYJUā€˜S free classes today!
C
Stack
No worries! Weā€˜ve got your back. Try BYJUā€˜S free classes today!
D
Queue
No worries! Weā€˜ve got your back. Try BYJUā€˜S free classes today!
Open in App
Solution

The correct option is A Heap
Heap and priority queue are very neat data structure allowing:
  • Add an element to heap with an associated priority.
  • Remove the element from the heap or priority queue that has the highest priority, and return it.
  • Peak at the element with highest priority without removing it. A simple way to implement a heap or priority queue data type is to keep a list of elements, and search through the list for the highest priority which gives O(n) time to implement Dijkstra's shortest path algorithm on unweighted graph.

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Difference of Sets
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon