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.
No. Consider the absolute worst-case where T looks something like this:
y
\
y
\
...
\
x
where the y
s 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 y
s 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.