Tuesday, April 3, 2007

Lecture 29


  • somewhat trickier than MergeSort
    • join is trivial
    • all the action happens in split
  • in QuickSort , split sorts the elements into bins
  • all the list elements less than the given number is the 'pivot'
  • all the list elements Greater than a given number
  • all list elements equal to the pivot
  • choose the pivot arbitrarily from one of the list elements



choose 4 as pivot

low - 3,2
high - 9,8,7
pivot - 4

concatenate the list in order

sort(pivot + high)

  • pivot list is guaranteed to have at least one element(the pivot)
  • i want both split lists to be smaller than the initial list
    1. low list is non empty
      1. split between low and pivot
    2. if low is empty but high is not
      1. split between pivot and high
    3. if both low and high are empty then split somewhere in middle of pivot

No comments: