lect_25 - Recursive Algorithms II Margaret M Fleck 29 March...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Recursive Algorithms II Margaret M. Fleck 29 March 2010 This lecture wraps up our discussion of algorithm analysis (section 4.4 and 7.1 of Rosen). 1 Announcements Quiz should be graded soon. More information as soon as I have clear infor- mation about how close to done it is. Homework 8 is posted, due this Friday. Reminder that honors homework 2 is due next Monday (the 5th). The second midterm will be a week from Wednesday (7 April). 7-9pm in 141 Wohlers, just like the first midterm. Study materials will be posted very soon. If you need special arrangements (e.g. extra time), contact me and (if necessary) book a room at DRES. Our final exam will be 7-10pm on Friday May 7th. The conflict final will be Monday the 10th, 1:30-4:30pm. As the end of term approaches, watch for further instructions (e.g. because the main exam involves two rooms in different buildings). 2 Recap Last lecture, we started talking about mergesort, a sorting algorithm whose big-O running time is O ( n log n ), i.e. better than the O ( n 2 ) running time of bubblesort and insertion sort. This is, in fact, the best big-O running time you can have for a sorting algorithm. The idea behind mergesort is to divide the (big) input list into two half- size lists. We keep dividing in half until we have a large collection of very 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
small lists. In our pseudo-code these base-case lists will be length 1. Real implementations often stop with lists of length 2 or even slightly longer, because it is easy to write code to directly sort very short lists. Once the tiny lists are all sorted (which is automatically true for lists of length 1), then we start merging them back together. We first merge the tiny lists in pairs to make lists twice as long. We keep merging pairs together until we get one big (sorted) list. [quick demo of the algorithm for merging two sorted lists] For sorting small to medium lists of numbers, the O ( n 2 ) quicksort al- gorithm typically runs fastest, because it has an average running time of O ( n log n ) and very good constants. Mergesort’s constants are only so-so. Mergesort is interesting because it’s has O ( n log n ) worst-case running time and is easy to analyze. Also, because the key merge step accesses its three lists in storage order, variations of this technique are used when sorting data that is stored in places that are slow to access. In the Bad Old Days, “slow storage” was usually magnetic tapes. These days, it’s often places that are somewhere else on the internet.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern