1

Here is the problem:

Let T be a splay tree on n nodes, and let x be a node of T. Consider a splay operation at x. Does the subtree under x become necessarily balanced (i.e., the height of the subtree rooted at x in the splay tree becomes O(logn) after the splay operation?

I spent lots of time on it, but still frustrated....I appreciate your answer.

Bi Wu
  • 55
  • 5
  • If you have another question, that you can't figure out on your own editing someone's answer isn't the right thing to do. You can always ask another question. – dcaswell Oct 18 '13 at 03:39

2 Answers2

2

No. Consider the absolute worst-case where T looks something like this:

y
 \
  y
   \
   ...
     \
      x

where the ys are arbitrary nodes. Once you splay x, the tree will look something like this:

  x
 /
y
 \
  y
 / \
y   y
   / \
  y   y
     / \
    y  ...
         \
          y

(again, with ys as arbitrary nodes). The depth then, is still O(n) in this case.

EDIT: Realized I messed up the "after" tree, so updating my answer with a more correct example.

Dennis Meng
  • 5,109
  • 14
  • 33
  • 36
  • Thank you. Dennis. It's helpful. So, after the splay operation, T should be like this: x / y \ y / \ y y / y... which is not balanced, right? – Bi Wu Oct 18 '13 at 02:24
  • A comment isn't the best place to try to draw a tree. I added the "before" and "after" in my answer so that it would be visible for both of us. – Dennis Meng Oct 18 '13 at 02:39
  • @BiWu With regards to that example you tried to give in that rejected edit; try again with a longer tree; you'll see the pattern. – Dennis Meng Oct 18 '13 at 03:54
  • Thanks~ I'll make a try. Just takes some time :) – Bi Wu Oct 18 '13 at 03:59
0

No. See these notes. The average depth of traversed nodes is cut in half, but that doesn't guarantee that a balanced tree results.

pjs
  • 18,696
  • 4
  • 27
  • 56