1

I'm studying for some technical interviews coming up and was just going over lecture slides from a year or two ago about data structures.

I'm not clear on why the worst case runtimes of merge for a leftist heap is O(log n) whereas for a skew heap it is O(n), when a skew heap essentially merges in the same way as a leftist heap.

A leftist heap merges A and B by picking the tree with the smaller root and recursively merging its right subtree with the larger tree. Then it checks the null path lengths and swaps its two subtrees if it violates leftist structure property.

A skew heap does the same thing but blindly swaps its two subtrees every time as it recursively merges A and B.

Why would the worst case of merge for a skew heap become O(n)? Is it because we can't guarantee a height bound as it recursively merges (since it's swapping sides every time)? Does this have to do with Floyd's Algorithm, that the sum of the heights from all nodes in a tree grows in O(n)?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
imyjimmy
  • 711
  • 2
  • 11
  • 18
  • I don't really remember these structures well enough to answer, but I can tell you that I've been on a few technical interviews and from what I've seen I would be surprised it this came up. The detailed nature of your question alone shows a pretty good understanding, and you're time spent prepping for these interviews would probably be better spent elsewhere. It depends on the nature of your job of course, but from what I've seen emphasis on threads/processes/concurrency is likely. – jon_darkstar Nov 14 '10 at 00:37

1 Answers1

1

leftist heap has a right path of length at most log(N+1). While skew heap's right path can be arbitrarily long(it can be N). Since the performance of merge depends on the length of the right path, so the worst-case merge times are like this. However, I don't know how skew heap does find. Can you give me some special case that the right path of skew heap is as long as N?

Stan
  • 11
  • 1