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

cs 241 data organization more trees
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS 241 Data Organization More trees

March 29, 2018

slide-2
SLIDE 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 time

  • f

to their all good come aid party

slide-3
SLIDE 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.

slide-4
SLIDE 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
  • perations run in O(log n) time.
slide-5
SLIDE 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.

slide-6
SLIDE 6

AVL tree: Example

A 3 4 B C 5 D A 3 B 4 C 5 D

slide-7
SLIDE 7

AVL tree: Example

A 3 B 4 C 5 D A 3 B 4 5 C D