Saturday, November 30, 2013

Insertion and Search

Insertion probably has the simplest implementation. We start by doing a standard binary tree insert, then splay the newly inserted node.

Searching is slightly less simple, as we modify the tree regardless of whether the item is present in the tree or not. We start with a standard binary search, after which we perform one of two possible operations. In the case that we found the node we were looking for, we splay it and return it. Otherwise, we splay the last node that was visited while searching. This is useful later during deletion.

Splaying

Splaying is the process that makes splay trees unique from a standard binary tree:

Splaying is a recursive function which takes node x and rotates it to the root of the tree.

Splaying performs three rotation types; Zig rotations, Zig-Zag Two rotations, and Zig-Zag rotations. Zig rotations are single rotations that occur when x is the left child of its parent, which is the root node. Zig-Zig rotations is a double zig rotation that occurs when node x is the left child of its parent, which is the left child of x's grandparent. Lastly, Zig-Zag rotations are double rotations that occur when node x is the right child of its parent, which is the left child of x's grandparent.

Disadvantages

Here's some of the disadvantages of splay trees.

A big one is that there is a possiblity of a tree having linear
height, which is something that other trees always
prevent. Another disadvantage is that the we normally think of a
search operation as nondestructive, that is, it doesn’t modify
the tree, but in the case of splay trees, it does. The most
obvious situation where this can become an issue is in a
multithreading environment. Finally, splay trees have the
disadvantage that individual operations can be expensive.  For
example, it is possible for a search to take time O(n) the
first time it runs, then O(1) the next time.

Advantages

Here's some of the advantages of splay trees.

First of all, splay trees are much simpler to implement than
other trees such as AVL or red-black trees.  They are basically
plain old binary search trees with one extra operation,
splaying. In the average case, they have performance comparable
to other balanced trees, and they also have a small memory
footprint as they use no more memory than a plain binary search
tree.  For comparison, every node of an AVL tree has an
additional height field, and every node of a red-black tree has
an additional color field. Finally, splay trees have no issue
with identical keys, wheres AVL trees, for example, do not
support identical keys.

Wednesday, November 27, 2013

Main Source

We should probably use the original paper for most of our information. There's a lot of other wrong information on other sites. Here's the link:
http://www.cs.princeton.edu/courses/archive/fall07/cos521/handouts/self-adjusting.pdf