Radix Sort, CHULL
Radix Sort, CHULL
Radix sort, CHULL Radix sort Convex hull by graham scan [Pictures] Convex hull angular graham scan [Pictures; esp. backtracking pic, and DOUBLE backtracking pic] Comparing angles [Diagrams, code fragments] Reduction from sorting to CHULL CHULL is Omega(n log n) Radix sort explanation: to sort a deck of cards from ace of clubs to king of spades, you can first sort numerically: put all the aces in one pile, all the twos in another pile, and so on. Then pick up the piles (in order) and sort into clubs, diamond, hearts and spades. When youre done, each SUIT will already be ordered A,2,3,4,,J, Q, K. ; Thats RADIX sort: if your data can be seen as broken into digits (like base 10 numbers, or like cards, where the first digit is the suit, and the second digit is the number), you can do the following: for place = least significant to most significant foreach item in list place it in a bucket according to its digit value in the current place concatenate all place-buckets, in order, into the now-empty list the list is now sorted. Application: lottery at Brown. Everyone can enter as often as they want. Need to find number of entries for each person. McBee Cards Convex hull Warmup: CCW(P, Q, R): Graham scan Find leftmost and rightmost points Sort all points left-to-right build upper hull and lower hull and glue together when done Building upper hull: o work from left to right. When you encounter a point P, add it to the upper hull. while there are at least 3 points AND the last turn in the hull is left, delete the second-to-last point Lower hull is similar, but you have to look for right turns instead.
Running time: n log n for the sorting; O(1) to insert point. After insertion, possibly O(n) deletion stepssounds like O(n^2). But actually, the TOTAL number of deletions in the entire process is no more than n, so its O(n) [total]. Combined with the sorting: O(n log n).