CS241: Spring 2015 -- Lecture 17, quick sort and merge sort

  1. Quick sort pseudocode
    	quickSort(List aList) {
    		if (size>1) {
    			select a pivot and split aList into head and tail (where everything in head is < pivot...) with the pivot in between
                            quickSort(head)
                            quickSort(tail)
    		}
    	}
            
  2. quicksorting 3,0,1,8,7,2,5,4,9,6 (in place)
  3. Merge sort pseudocode
    	mergeSort(List aList) {
    		if (size>1) {
    			split aList roughly in half creating head and tail
                            mergeSort(head)
                            mergeSort(tail)
    			merge head and tail
    		}
    	}
            
  4. mergesorting 3,0,1,8,7,2,5,4,9,6 (in place)
  5. From pseudocode to code; details! It's all about the details! No. First it's about the representation; after you choose that, it's about the details.
    1. starting -- also known as initializing
    2. stopping
    3. in between
  6. Proactive debugging
    1. souts on enter and exit to recursive routines; like this:
          void foo(int startI, int endI) {
              System.out.print("Top of foo: ");
              System.out.print(" startI = " + startI);
              System.out.print(" endI = " + endI);
              System.out.println(toString(startI, endI));
              
              ...foo code...
              
              System.out.print("bottom of foo: ");
              System.out.print(" startI = " + startI);
              System.out.print(" endI = " + endI);
              System.out.println(toString(startI, endI));       
          }
                      
    2. toString(firstI, lastI)
    3. shift(firstI, lastI)