Splay Tree - Demo Applet

The basic idea of the splay tree is that after a node is accessed, it is pushed to to the root by a series of rotations similar to AVL tree rotations. Notice that if a node is deep, there are many nodes on the path that are also relatively deep, and by restructuring we can make future accesses faster on all these nodes. Thus, if the node is unduly deep, then we want this restructuring to have the side effect of balancing the tree.

This applet demonstrates Splay Tree operations. However, it shows only the final result of self-restructuring (i.e. the most-recently-accessed data is promoted the root of the tree), not the sequence of rotations. In the history pane, however, it shows some detailed statistics of the performed rotations. So, it's better to draw your own picture and compare it with the applet demo.

Notes on source codes: The implementation is not dedicated to Splay Tree data structure itself. Instead, the splay tree class is embedded in the java applet class with some other optional methods for demonstration purpose. Also, note that the source codes is not efficiently written in terms of complexity of running time, and minor bugs are observed in DELETE method.   view source code (to download, just right-click on the link and save it as .java file)

Command Syntax :

RESET,  DELAY numberINSERT number,  FIND number,  DELETE number,  FIND-MIN,  FIND-MAX,  STAT-MODE

NOTE : All commands should be capitalized, and some commands involved numbers should be followed by a single space and then a integer number.
 

Execute the following commands to test INSERT, FIND, DELETE, FIND-MIN, and FIND-MAX operation of the splay tree.
(COPY and PASTE the whole series of commands into the Text Area. Then, click on the Execute button)

Execute the following commands to test STAT-MODE, which shows interesting statistics of splaying in the history pane.

NOTE: Decreased Avg. depth is the depth of OLD FAMILY nodes of a splayed node - parent, sibling, and left, right child, NOT the whole tree. In that way, we can see how the data near the most-recently-accessed data are improved for a faster access in future by the side effect of splaying.


by Hyung-Joon Kim, CSE373, University of Washington