This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Algorithms in Systems Engineering IE170 Lecture 8 Dr. Ted Ralphs IE170 Lecture 8 1 References for Todays Lecture Required reading CLRS Chapter 7 References D.E. Knuth, The Art of Computer Programming, Volume 3: Sorting and Searching (Third Edition), 1998. R. Sedgewick, Algorithms in C++ (Third Edition), 1998. IE170 Lecture 8 2 Quicksort We now discuss a sorting algorithm called quicksort similar to one that we saw in Lab 2. The basic quicksort algorithm is as follows. Choose a partition element. Partition the input array around that element to obtain two subarrays. Recursively call quick sort on the two subarrrays. Here is code for the basic algorithm. void quicksort(Item* data, const int l, const int r) { if (r <= l) return; int i = partition(data, l, r); quicksort(data, l, i1); quicksort(data, i+1, r); } IE170 Lecture 8 3 Partitioning One big advantage of quicksort is that the partitioning (and hence the entire algorithm) can be performed in place. Here is an in place implementation of the partitioning function. IE170 Lecture 8 4 Analyzing Quicksort Questions to be answered How do we prove the correctness of quick sort? Does quicksort always terminate? Can we do some simple optimization to improve performance? What are the best case, worst case, and average case running times?...
View Full
Document
 Spring '07
 Ralphs
 Systems Engineering

Click to edit the document details