cs 241 data organization more trees
play

CS 241 Data Organization More trees March 29, 2018 Removing Node - PowerPoint PPT Presentation

CS 241 Data Organization More trees March 29, 2018 Removing Node from Ordered Tree How can we remove an item from this tree, keeping it ordered? aid? of? the? now is the for men of time all good party their to aid come Three


  1. CS 241 Data Organization More trees March 29, 2018

  2. Removing Node from Ordered Tree How can we remove an item from this tree, keeping it ordered? aid? of? the? now is the for men of time all good party their to aid come

  3. Three possible cases • Node has no children (is a leaf): Just remove the node. • Node has one child: Remove node, replace with child. • Node has two children: Replace value in node with value from in-order successor (or predecessor) node and delete that node instead.

  4. Balanced Binary Tree • A binary tree is balanced if height of left and right children of every node differ by at most 1. • A balanced BST has height of O (log n ), so operations run in O (log n ) time.

  5. AVL Tree • An AVL tree is a self-balancing binary search tree. • Named after its Soviet inventors: Adelson-Velskii and Landis • Add/remove as usual, but follow with tree rotations to restore balance.

  6. AVL tree: Example 5 5 3 D 4 D A 4 3 C B C A B

  7. AVL tree: Example 5 4 3 5 4 D A B C D 3 C A B

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend