CS210 · Annotated SlidesTrees — Binary Search Trees
Trees · Annotated slides

Binary Search Trees

BST definition, search and insert (Java), tree shape and its effect on cost, lazy deletion, deleting the minimum, and Hibbard deletion.

Slide text Study notes Highlight: key words Tips, tricks & traps Seen again elsewhere How it can come up
Slide 1: A l g o r i t h m s
Exam weight Low
    Slide 2: Slide 2
    Exam weight Low
      Slide 3: must
      Exam weight Low
      1. BST: every node’s key is larger than all keys in its left subtree and smaller than all in its right.
      Slide 4: Binary search tree demo
      Exam weight Low
        Slide 5: Binary search tree demo
        Exam weight Low
          Slide 6: BST representation in Java
          Exam weight Low
            Slide 7: BST implementation (skeleton)
            Exam weight Low
              Slide 8: BST search: Java implementation
              Exam weight Low
              1. Search: compare and go left or right; cost = depth.
              Slide 9: Slide 9
              Exam weight Low
                Slide 10: BST insert
                Exam weight Low
                  Slide 11: Slide 11
                  Exam weight Low
                    Slide 12: BST insert: Java implementation
                    Exam weight Low
                      Slide 13: Tree shape
                      Exam weight High
                      1. Shape depends on insertion order: random → ~1.39 lg N; sorted order → a path (N).
                      🎯 How this can come up · 1 question
                      MCQ

                      Inserting 1, 2, 3, 4, 5 in order into an empty BST gives height:

                      Slide 14: BST insertion: random order visualization
                      Exam weight Low
                        Slide 15: BSTs: mathematical analysis
                        Exam weight Low
                          Slide 16: ST implementations: summary
                          Exam weight Low
                          1. BST: average O(log N), worst O(N) for search and insert.
                          Slide 17: Slide 17
                          Exam weight Low
                            Slide 18: ST implementations: summary
                            Exam weight Low
                              Slide 19: BST deletion: lazy approach
                              Exam weight Low
                                Slide 20: Slide 20
                                Exam weight Low
                                  Slide 21: Deleting the minimum
                                  Exam weight Low
                                  1. Delete min: go left until null left link, replace that node by its right link.
                                  Slide 22: Hibbard deletion
                                  Exam weight High
                                  1. Hibbard deletion: 0 children → remove; 1 child → replace with child; 2 children → replace with successor (min of right subtree).
                                  🎯 How this can come up · 1 question
                                  Written

                                  How do you delete a node with two children from a BST?

                                  Slide 23: Slide 23
                                  Exam weight Low
                                    Slide 24: Slide 24
                                    Exam weight Low
                                      Slide 25: Simlevernoses
                                      Exam weight Low
                                        Slide 26: Hibbard deletion
                                        Exam weight Low
                                          Slide 27: Hibbard deletion
                                          Exam weight Low
                                            Slide 28: Hibbard deletion: Java implementation
                                            Exam weight Low
                                              Slide 29: Hibbard deletion: analysis
                                              Exam weight Low
                                              1. Hibbard deletion makes trees unbalanced over time (√N height).
                                              Slide 30: commissiics
                                              Exam weight Low
                                                Slide 31: Slide 31
                                                Exam weight Low