Previous Lecture Lecture 18

Lecture 18, Thu 03/07

Quicksort, Binary Search Tree Deletion

Slides folder

Recording

Quicksort

Partition the list into left/right sublists

  1. Choose pivot (typically first element in list)
  2. leftmark index is on left-most side of list, rightmark index is on right-most side of list, and both leftmark and rightmark work inwards
  3. Find an element in the left side (using leftmark index) that’s out-of-place (> pivot)
  4. Find an element in the right side (using rightmark index) that’s out-of-place (< pivot)
  5. Swap out-of-place elements with each other
    • We’re putting them in the correct side of the list!
  6. Continue doing steps 1 - 5 until the rightmark index < leftmark index
  7. Swap the pivot with rightmark index
    • We’re putting the pivot element in the correct place!

Example

quicksort_example

Quicksort Analysis

BST Deletion

Case 1: Deleting a leaf node

bstdelete_leaf

Case 2: Deleting a node with 1 child

bstdelete_1child

Case 3: Deleting a node with 2 children

bstdelete_2chldren