CSC151 2007S, Class 48: Merge Sort Admin: * Quiz 9 returned (finally) * Are there questions on Exam 3? * EC for * Attending the stats poster session Thursday at 11:00 in the Science elbow. * Thursday's Thursday extra (the last of the semester). * Collaborative THING tomorrow night Flanagan at 7:00ish * GIMP presents Children of Eden Thursday and Friday at 7:00, Sunday at 2:00 * Children friendly * Free tickets in box office * Herrick * Javanese Music Ensemble Saturday at 2:00 in Sebring-Lewis * G-Motion Friday at 8:00 in Harris * Sunday: GC Triathalon * It's 30-something this morning. It's supposed to dip below freezing tonight. Welcome to spring in Ioway. * I'd like to hear your thoughts on the ad on p. 3 of Friday's S&B. We edit for structur Overview: * More efficient sorting techniques. * Divide and conquer, revisited. * Merge sort. * Analyzing merge sort. * Lab! ==Exam QUestions== Q: On Problem 10, can we find the largest element by sorting and then taking the last element? A: Clever, but NO! Since we're using largest to implement a sorting algorithm ==Quiz== (cons (cons 'banana (cons 'apple null)) 'orange) (define myproc (lambda (tree) (if (pair? tree) (+ (myproc (car tree)) (myproc (cdr tree)) (if (equal? tree 'banana) 1 0))))) ==Sorting, Reviewed== * Goal: Put things in order (in a list or vector) * How do we determine the order? With a procedure that compares two values may-precede? (sort list-or-vector may-precede?) * Our first sorting techniques took approximately N^2 comparisons ==More Efficient Sorting Techniques== * When confronted with an N^2 algorithm, we ask "Can we do better?" * Technique one: Look for other algorithms * Technique two: Prove that you can't do better ==Divide and Conquer== * In the merge sort technique, we split our data, sort the two halves, and join them * How do we split a vector, anyway? * In the middle ==Merge Sort, Revisited=== ==Analyzing Merge Sort== * N*log2N * AND THAT'S THE BEST YOU CAN DO IN A COMPARISON-BASED ALGORITHM