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.