SplayTrees - Splay Trees are Binary Search Trees Splay...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Splay Trees 1 Splay Trees 6 3 8 4 v z Splay Trees 2 all the keys in the yellow region are 20 all the keys in the blue region are 20 Splay Trees are Binary Search Trees ± BST Rules: ² items stored only at internal nodes ² keys stored at nodes in the left subtree of v are less than or equal to the key stored at ² keys stored at nodes in the right subtree of are greater than or equal to the key stored at ± An inorder traversal will return the keys in order (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) note that two keys of equal value may be well- separated Splay Trees 3 Searching in a Splay Tree: Starts the Same as in a BST ± Search proceeds down the tree to found item or an external node. ± Example: Search for time with key 11. (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) Splay Trees 4 Example Searching in a BST, continued ± search for key 8, ends at an internal node. (20,Z) (37,P) (21,O) (14,J) (7,T) (35,R) (10,A) (1,C) (1,Q) (5,G) (2,R) (5,H) (6,Y) (5,I) (8,N) (7,P) (36,L) (10,U) (40,X) Splay Trees 5 Splay Trees do Rotations after Every Operation (Even Search) ± new operation: splay ² splaying moves a node to the root using rotations ² right rotation ² makes the left child x of a node y into y ’s parent; y becomes the right child of x y x T 1 T 2 T 3 y x T 1 T 2 T 3 ² left rotation ² makes the right child y of a node x into x ’s parent; x becomes the left child of y y x T 1 T 2 T 3 y x T 1 T 2 T 3 (structure of tree above y is not modified) (structure of tree above x
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/24/2010 for the course CS cs 5329 taught by Professor Wang during the Spring '10 term at Southwest Texas Junior College.

Page1 / 3

SplayTrees - Splay Trees are Binary Search Trees Splay...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online