CS 225 Data Structures Oct. 13 AVL Rotations BST Reflection We - - PowerPoint PPT Presentation

cs 225
SMART_READER_LITE
LIVE PREVIEW

CS 225 Data Structures Oct. 13 AVL Rotations BST Reflection We - - PowerPoint PPT Presentation

CS 225 Data Structures Oct. 13 AVL Rotations BST Reflection We know the height of a tree. We know if a tree is full , complete , and/or perfect . We know that every binary tree has ________ NULL pointers. We know many traversals of trees. We


slide-1
SLIDE 1

CS 225

Data Structures

  • Oct. 13 – AVL Rotations
slide-2
SLIDE 2

BST Reflection

We know the height of a tree. We know if a tree is full, complete, and/or perfect. We know that every binary tree has ________ NULL pointers. We know many traversals of trees. We know that a BST’s height is bound by n such that: _____ ≤ h ≤ _____ We know all key BST operations run in O(h) time. We know a BST can be used to implement a Dictionary. We know that a random BST has an average height of _____. We know that an inorder traversal of a BST is a __________. We know how to implement a BST in C++.

slide-3
SLIDE 3

Height-Balanced Tree

What tree makes you happier? Height balance: b = height(TR) - height(TL) A tree is height balanced if:

9 5

7

7

5

9

slide-4
SLIDE 4

13 10 25 38 51 40 84 89 66 95

slide-5
SLIDE 5

BST Rotation

We will perform a rotation that maintains two properties: 1. 2.

slide-6
SLIDE 6

13 10 25 38 51 40 84 89 66 95

slide-7
SLIDE 7

13 10 25 38 51 84 89

A B C D

slide-8
SLIDE 8

13 10 25 38 51 84 89

A B C D

84 51 89

A B C D

slide-9
SLIDE 9

13 10 25 38 51 40 84 89 66 95

slide-10
SLIDE 10

13 10 25 37 38 51

slide-11
SLIDE 11

13 10 25 37 38 51

slide-12
SLIDE 12

BST Rotation Summary ry

  • Four kinds of rotations (L, R, LR, RL)
  • All rotations are local (subtrees are not impacted)
  • All rotations are constant time: O(1)
  • BST property maintained

GOAL: We call these trees:

slide-13
SLIDE 13

AVL Trees

Three issues for consideration:

  • Rotations
  • Maintaining Height
  • Detecting Imbalance
slide-14
SLIDE 14

5 3 6 4 2 8 10 9 12 11 1

slide-15
SLIDE 15

t

t1 t2 t3 t4

Theorem: If an insertion occurred in subtrees t3 or t4 and a subtree imbalance was detected at t, then a __________ rotation about t restores the balance

  • f the tree.

We gauge this by noting the balance factors: t: b=______ t->right: b=______

slide-16
SLIDE 16

CS 225 – Things To Be Doing

Exam 5 (Theory) is ongoing!

More Info: https://courses.engr.illinois.edu/cs225/fa2017/exams/

MP4: Available later today!

Due: Monday, Oct. 23 at 11:59pm

Lab!

Due: Sunday, Oct. 15 at 11:59pm

POTD

Every Monday-Friday – Worth +1 Extra Credit /problem (up to +40 total)