We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Dijkstra's algorithm for shortest path and Prim's algorithm for finding a minimum spanning tree are usually considered applications of heaps, even though they could be implemented with binary trees. Heaps are more efficient. They require kkworden's technique of providing a table or dictionary for looking up the current location of an element with the given identifier. The heap operations 'reduce-key' and 'delete' require the table. See Cormen, Leiserson, Rivest, Stein, "Introduction to Algorithms," third edition. So there are a lot of reasons to do it the way the problem setter has suggested.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
Dijkstra's algorithm for shortest path and Prim's algorithm for finding a minimum spanning tree are usually considered applications of heaps, even though they could be implemented with binary trees. Heaps are more efficient. They require kkworden's technique of providing a table or dictionary for looking up the current location of an element with the given identifier. The heap operations 'reduce-key' and 'delete' require the table. See Cormen, Leiserson, Rivest, Stein, "Introduction to Algorithms," third edition. So there are a lot of reasons to do it the way the problem setter has suggested.