Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Splay tree
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Operations == === Splaying === When a node ''x'' is accessed, a splay operation is performed on ''x'' to move it to the root. A splay operation is a sequence of ''splay steps'', each of which moves ''x'' closer to the root. By performing a splay operation on the node of interest after every access, the recently accessed nodes are kept near the root and the tree remains roughly balanced, so it provides the desired amortized time bounds. Each particular step depends on three factors: * Whether ''x'' is the left or right child of its parent node, ''p'', * whether ''p'' is the root or not, and if not * whether ''p'' is the left or right child of ''its'' parent, ''g'' (the ''grandparent'' of ''x''). There are three types of splay steps, each of which has two symmetric variants: left- and right-handed. For the sake of brevity, only one of these two is shown for each type. (In the following diagrams, circles indicate nodes of interest and triangles indicate sub-trees of arbitrary size.) The three types of splay steps are: '''Zig step:''' this step is done when ''p'' is the root. The tree is rotated on the edge between ''x'' and ''p''. Zig steps exist to deal with the parity issue, will be done only as the last step in a splay operation, and only when ''x'' has odd depth at the beginning of the operation. [[File:splay tree zig.svg|center|350px]] '''Zig-zig step:''' this step is done when ''p'' is not the root and ''x'' and ''p'' are either both right children or are both left children. The picture below shows the case where ''x'' and ''p'' are both left children. The tree is rotated on the edge joining ''p'' with ''its'' parent ''g'', then rotated on the edge joining ''x'' with ''p''. Zig-zig steps are the only thing that differentiate splay trees from the ''rotate to root'' method introduced by Allen and Munro<ref name="AllenMunro">{{harvnb|Allen|Munro|1978}}.</ref> prior to the introduction of splay trees. [[Image:Zigzig.gif|center]] '''Zig-zag step:''' this step is done when ''p'' is not the root and ''x'' is a right child and ''p'' is a left child or vice versa (''x'' is left, ''p'' is right). The tree is rotated on the edge between ''p'' and ''x'', and then rotated on the resulting edge between ''x'' and ''g''. [[Image:Zigzag.gif|center]] === Join === Given two trees S and T such that all elements of S are smaller than the elements of T, the following steps can be used to join them to a single tree: * Splay the largest item in S. Now this item is in the root of S and has a null right child. * Set the right child of the new root to T. === Split === Given a tree and an element ''x'', return two new trees: one containing all elements less than or equal to ''x'' and the other containing all elements greater than ''x''. This can be done in the following way: * Splay ''x''. Now it is in the root so the tree to its left contains all elements smaller than ''x'' and the tree to its right contains all element larger than ''x''. * Split the right subtree from the rest of the tree. === Insertion === To insert a value ''x'' into a splay tree: * Insert ''x'' as with a normal [[binary search tree]]. * Perform a splay on ''x''. As a result, the newly inserted node ''x'' becomes the root of the tree. Alternatively: * Use the split operation to split the tree at the value of ''x'' to two sub-trees: S and T. * Create a new tree in which ''x'' is the root, S is its left sub-tree and T its right sub-tree. === Deletion === To delete a node ''x'', use the same method as with a binary search tree: * If ''x'' has two children: ** Swap its value with that of either the rightmost node of its left sub tree (its in-order predecessor) or the leftmost node of its right subtree (its in-order successor). ** Remove that node instead. In this way, deletion is reduced to the problem of removing a node with 0 or 1 children. Unlike a binary search tree, in a splay tree after deletion, we splay the parent of the removed node to the top of the tree. Alternatively: * The node to be deleted is first splayed, i.e. brought to the root of the tree and then deleted. leaves the tree with two sub trees. * The two sub-trees are then joined using a "join" operation.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Splay tree
(section)
Add topic