Introduction to Algorithms, Second Edition

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

The University of Texas at Austin Lecture 6 Department of Computer Sciences Professor Vijaya Ramachandran Randomized Quicksort CS357: ALGORITHMS, Spring 2006 Randomized Partition and Randomized Quicksort Randomized-Partition is a simple modification of Partition (which was defined earlier) in which a random element in the subarray being considered is moved to the last position in the subarray (hence this element becomes the pivot), and then Partition is invoked. Rand-Partition ( A, p, r ) i := Random ( p, r ) interchange A [ i ] and A [ r ] return Partition ( A, p, r ) Correctness of Rand-Partition is immediate once we assume correctness of Partition , since A [ i ] is guaranteed to be an element in the subarray A [ p..r ]. The running time remains linear in the size of subarray. We now use Rand-Partition in the randomized version of Quicksort given below. Rand-Quicksort ( A, p, r ) Input. An array A [1 ..n ] of elements from a totally ordered set; p and r are integers with 1 p r n . Output. The elements in sub-array A [ p..r ] are rearranged in sorted order; the elements in array A outside of subarray A [ p..r ] are unchanged. (So initial call is to A [1 ..n ].) if p < r
Image of page 1

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

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '06
  • Ramachandran
  • Algorithms, Sort, Probability theory, Pivot element, Rand-Partition

{[ 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