This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Illinois Institute of Technology Department of Computer Science Lecture 5: February 4, 2009 CS 430 Introduction to Algorithms Spring Semester, 2009 1 More on quicksort: other efficiency metrics In the previous lecture we arrived at an expression for the efficiency of quicksort by counting the number of comparisons. There are a number of other metrics we can use, though. 1.1 Exchanges For instance, we can count the number of exchanges that take place. If we view the partition algorithm as a sequence of exchanges, 1 we can count the number of exchanges that are performed on the array. In the worst case, ¥ n 2 ¦ exchanges take place at each level of the recursion. We have the recurrence E ( n ) = E ³j n 2 k´ + E ³l n 2 m´ + j n 2 k where E (0) = E (1) = 0. It turns out that this recurrence has a nice solution: E ( n ) = n 1 X i =0 ν ( i ) where ν ( i ) is the number of 1bits when i is written in binary, clearly no greater than d lg i e . Dividing by n , E ( n ) n = 1 n n 1 X i =0 ν ( i ) which is the average number of 1bits in i written in binary. This is approximately 1 2 lg n , so we have E ( n ) n ≈ 1 2 lg n E ( n ) ≈ 1 2 n lg n = Θ( n log n ) 1.2 Stack depth The expected depth of the recursion stack is somewhat simpler. Although the algorithm makes two recursive calls, the two calls are not made at the same time. This yields a recurrence of S ( n ) = 1 + 1 n n 1 X i =0 S ( i ) 1 The Partition algorithm given in section 7.1 of CLRS uses this approach. CS 430—Spring, 2009 2 Lecture 5: February 4, 2009 which can be solved as we solved the (more complex) runningtime recurrences for quicksort, giving S ( n ) = O (log n ) 2 Divide and conquer The divideandconquer paradigm is used often in the formulation of algorithms. A divideandconquer algorithm will typically involve splitting a problem into smaller components ( divide ), solving the problem on those components ( conquer ), and combining the results in some meaningful fashion ( combine )....
View
Full
Document
This note was uploaded on 04/07/2009 for the course CS 430 taught by Professor Kapoor during the Spring '08 term at Illinois Tech.
 Spring '08
 KAPOOR
 Algorithms, Sort

Click to edit the document details