1 / 8

Chapter 4: Trees

Mark Allen Weiss: Data Structures and Algorithm Analysis in Java. Chapter 4: Trees. AVL Trees. Lydia Sinapova, Simpson College. 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.

tam
Download Presentation

Chapter 4: Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. 5 3 7 6 8 9 Single Rotation 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) New node Links to be changed

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

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

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

  7. E I R S A C G H N 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

  8. Complexity Issues • AVL trees: Search,Insertion, and Deletion:O(logN) Creating the tree – O(N) • Trees withmultiple keys: O(LogmN) m – branching factor

More Related