CSC151.01 2006S, Class 45: Quicksort Admin: * Due: HW15. * Assigned: HW16 (the last part of this lab). *** HW16 is the last homework for 151 *** * Reading: Variable-Arity Procedures. * Post-Preregistration hints * Today's prospies: * Alex * Is it warmer there? "Eeeh" * Where else: Pomona, UC Bezerkeley * TJ * Is it warmer there? "Oh yeah" * Lewis and Clark (in Oregon) (as opposed to the many other Lewis's and Clarkses) Overview: * The key ideas of Quicksort. * Lab. /Key Ideas/ * Split lists (yay "Divide and conquer") * Split using a "random pivot" * A random border between left and right * Into things that are smaller than the pivot and larger than the pivot * Simulates the median * What is the median? * The one in the middle of a sorted list * The one for which half the numbers are smaller and half are larger * Whoops, hard to compute /Lab/ Observation: When we insertion-sort a list of 50 values, it does about 666 calls to the may-precede? procedure. Why? * Why is it so large? * Why does it vary? * BG: How does insertion sort work? * We have a sorted list and an unsorted list and repeatedly insert into the sorted list. * Suppose there are k elements in the sorted list. How many times do we call may-precede? to insert. * On average, k/2 * But it varies depending on where in the list the value gets inserted. * For a list of length 50 ... 0 + 1/2 + 2/2 + 3/2 + 4/2 + ... + 49/2 (50*49/2)/2 approximately 2500/4 approximately 625