Splay trees Go&Ta 10.3
How do you organize your world?
“move to front” heuristic …
splay trees A method that modifies a binary search tree (bst) Something like a rotation in AVL There are 3 operations: zig-zig, zig-zag, and zig
splay treeszig-zig T2 T3T4 T1 z y x x and y are right children (or left children, symmetry)
splay treeszig-zig T2 T3T4 T1 z y x T2 T3 T4 T1 z y x zig-zig
splay treeszig-zag T4 T2T3 T1 z y x one of x and y is a left children and the other is a right child (also symmetry)
splay treeszig-zag T4 T2T3 T1 z y x T4 T2T3 T1 zy x zig-zag
splay treeszig T2 T3T4 T1 y x w x has no grandparent (also symmetry)
splay treeszig T2 T3T4 T1 y x w zig T4 T2T3 T1 yw x
splay trees We repeat these splay steps until x becomes the root When do we splay? we insert k into the bstree x is the new node with key k we search for k in the bstree x is node with key k or node where we stopped search we delete k from the bstree delete method ultimately removes a leaf the leaf is x
splay trees Advantages: frequently accessed data moves nearer to root the “move to front” heuristic average performance is O(log(n)) simple no additional information/data required add-on to bstree
splay trees Disdvantages: worst case height can be linear O(n)
splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?
splay treesrefresher Nodes in a Complete Binary Tree
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: …
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree For a complete binary tree that would be: …
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree
splay treesrefresher Nodes in a Complete Binary Tree depth #nodes totalNodes ^ ^2 – ^3 – ^4 -1 d 2^d 2^(d+1) - 1 internal path length is the sum of the length of the paths to all nodes in the tree Average path length is then O(log(n))
splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth?
splay trees Question: in our experiments with bstree and avl tree we measured height is that measure meaningful? is there a more useful measure, such as average depth? Answer: average depth would be more meaningful
splay trees Show me a demo