Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4: Trees AVL Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.

Similar presentations


Presentation on theme: "Chapter 4: Trees AVL Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java."— Presentation transcript:

1 Chapter 4: Trees AVL Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java

2 2 AVL Trees  Keep the tree balanced  Use node rotation  Balanced condition: The left and the right subtrees of each node should differ by at most one level. The method was proposed by two Russian scientists Adelson-Velskii and Landis in 1962

3 3 Single Rotation 5 3 7 68 9 The sub-tree containing the inserted node (rooted at 8) is at the same side as the ‘heavier’ sub-tree of node 5 (rooted at 7) Links to be changed New node

4 4 After the Rotation 7 5 8 963 The middle node 6 is switched to the other subtree

5 5 Double Rotation 5 6 7 8 5 78 9 6 9 8 8 7 7 The new node 6 is in the left subtree of node 8, while node 8 is the right subtree of 5 -> rotate 7 and 8 to obtain same-side trees. Animation New node

6 6 Splay Trees Move to the top each accessed node with rotations, decreasing the depth of the tree.

7 7 Multi-Way Search Nodes contain more than one key nodes are used only to contain the keys, the actual records are stored at the terminal nodes at the bottom of the tree E I R A C G H S N

8 8 Complexity Issues  AVL trees: Search,Insertion, and Deletion: O(logN) Creating the tree – O(N)  Trees with multiple keys: O(Log m N) m – branching factor


Download ppt "Chapter 4: Trees AVL Trees Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java."

Similar presentations


Ads by Google