When asked to design an algorithm please provide the pseudocode with enough explanation that it can be understood easily.
Given a splay tree T and a key x, top down splaying will move x (or if x is not in the tree, the node just before or just after x) to the root two levels at at time except for possibly one time moving one level. To splay T at the key x there are three cases. Case 1: x or the node where x would be inserted is at the root of T. In this case there is nothing to do, just return. Case 2: x or the node where x would be inserted is one level from the root of T. In this case simply rotate that node to the root. Case 3: x or the node where x would be inserted is at least two levels from the root. Now there are four subcases depending on the direction from the root the path to x follows. We consider just one of the four subcases, as the others are similar. Suppose the path to x or where x would be inserted is first right, then left. Replace T.right.left with the result of recursively top down splaying T.right.left at the key x. Now, double rotate to move x to the root (a right-zig-zag subcase).
You can assume that you have functions that rotate and double rotate in all directions.
Show the result of both bottom up and top down splaying at 14 on the following tree.
20 / \ 10 30 / \ / \ 5 15 25 35 / / \ 3 13 18 / 11