Lecture 5/27: Binary Search Trees


May 27, 2020

📂Associated files

Binary Search Trees

CS 106B: Programming Abstractions

Spring 2020, Stanford University Computer Science Department

Lecturers: Chris Gregg and Julie Zelenski

A binary search tree. 50 has children 17 and 72. 17 has children 12 and 23. 72 has children 54 and 76. 12 has children 9 and 14. 23 has a left child, 19. 54 has a right child, 67


Slide 2

Announcements


Slide 3

Today's Topics


Slide 4

Final Assessment plans


Slide 5

Mid-Quarter Feedback


Slide 6

Why the "binary search tree"


Slide 7

Binary Search Tree Definition


Slide 8

Binary Search Tree Functions


Slide 9

Easy functions: findMin() and findMax()


Slide 10

Easy function: contains(s)


Slide 11

Easy function (but there are multiple ways to do it): add(x)


Slide 12

Hard function: remove(s)

        6
      ↙︎  ↘︎
    2      8
  ↙︎  ↘︎
1      5
     ↙︎
    3
     ↘︎
       4

Slide 13

Have we created the perfect set?


Slide 14

Balancing Trees


Slide 15

Balancing Trees: left and right subtrees the same height?