Introduction to Algorithms, Second Edition

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

View Full Document Right Arrow Icon
The University of Texas at Austin Lecture 4 Department of Computer Sciences Professor Vijaya Ramachandran Quicksort; basic probability CS357: ALGORITHMS, Spring 2006 Quicksort 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. if p<r then q := Partition ( A, p, r ) Quicksort ( A, p, q - 1) Quicksort ( A, q +1 ,r ) To sort the entire array A [1 ..n ]weca l l Quicksort ( A, 1 ,n ). Partition ( A, p, r ) Let x be the element in A [ r ]when Partition is called; x is called the pivot element . Partition ( A, p, r ) returns an index q , p q r and rearranges the elements in subarray A [ p..r ] such that the following properties hold after execution: A [ q ]:= x For p i<q , A [ i ] x For q<i r , A [ i ] >x
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Lecture 4 - The University of Texas at Austin Department of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online