0

For my assignment, I have been working on a satnav system and I am using an adjacency list to store all of the mapping data.

I therefor want to implement dijkstras algorithm for my path planning functions but I need to first implement a min-priority queue. Is is possible to do this using a regular heap, or is a binary one needed?

StonerLoods
  • 121
  • 9
  • related (possible duplicate?): http://stackoverflow.com/questions/14252582/how-can-i-use-binary-heap-in-the-dijkstra-algorithm – Jim Mischel Apr 21 '16 at 12:15

2 Answers2

2

It seems you mean regular heap as memory region used for dynamic memory allocation. This term has no relation to the term heap as data structure (binary heap is particular case), which represents a set of values, ordered in specific manner

MBo
  • 77,366
  • 5
  • 53
  • 86
0

You can implement a min-priority queue with a regular (array-based) heap very easily, but Dijkstra's algorithm requires support for an additional operation: you have to be able to find any given item and dynamically lower its priority.

An array-based heap doesn't normally come with an efficient way to find any item except the root, so you need to add a way to do that.

An easy way is to maintain a 2nd array that contains the index of each item in the heap array (or -1 if the item isn't in the heap). You have to update this array whenever you add, remove, or swap heap items.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87