1

Can Prim's algorithm be implemented by treaps to speed up the execution because a normal heap would pose a problem in updating the value of keys while storing vertices in heaps which otherwise would require O(V) space to store location of vertices in heap?

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
silentseeker
  • 416
  • 5
  • 14
  • Can you elaborate? How would treaps help here? – templatetypedef Apr 13 '14 at 07:26
  • I will keep vertex as the key and weight as the value in a treap. See in treaps we can search a key in O(height) time,now when it will be required to update the minimum length path connecting a vertex, it will help me save space,otherwise it will be required to keep a look-up table to check where the vertex is stored in the heap – silentseeker Apr 13 '14 at 10:09

1 Answers1

1

This will not necessarily make Prim's algorithm any faster. Consider the following degenerate case - you have n nodes v1, v2, ..., vn, and their priorities are such that p(v1) < p(v2) < p(v3) < ... < p(vn). In that case, the treap will be a degenerate linked list, and if you need to update priorities along the way, simply looking up the nodes in the tree might take time Ω(n). A standard binary heap with an extra lookup table would be faster than this.

Sorry for the negative result, but I hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • Yeah I agree with you!! But can i expect better performance in an average case as like in case of randomized BST made out with random priorities assigned to new elements being added? – silentseeker Apr 14 '14 at 07:20
  • @silentseeker Well, no, I don't think so. That would give you an easy way to find each node, but not an easy way to find the node with the lowest cost so far. If you want to speed up Prim's algorithm, you probably should look into priority queues supporting efficient decrease-key, like the pairing heap. Those are quite fast in practice. – templatetypedef Apr 14 '14 at 07:23