{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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 v keys stored at nodes in the right subtree of v are greater than or equal to the key stored at v 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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern