11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 7.11 Exercises 259algorithm to modify the key values such th<strong>at</strong> every modified key value isunique, the resulting key values give the same sort order as the original keys,the result is stable (in th<strong>at</strong> the duplic<strong>at</strong>e original key values remain in theiroriginal order), <strong>and</strong> the process of altering the keys is done in linear timeusing only a constant amount of additional space.7.8 The discussion of Quicksort in Section 7.5 described using a stack instead ofrecursion to reduce the number of function calls made.(a) How deep can the stack get in the worst case?(b) Quicksort makes two recursive calls. The algorithm could be changedto make these two calls in a specific order. In wh<strong>at</strong> order should thetwo calls be made, <strong>and</strong> how does this affect how deep the stack canbecome?7.9 Give a permut<strong>at</strong>ion for the values 0 through 7 th<strong>at</strong> will cause Quicksort (asimplemented in Section 7.5) to have its worst case behavior.7.10 Assume L is an array, L.length() returns the number of records in thearray, <strong>and</strong> qsort(L, i, j) sorts the records of L from i to j (leavingthe records sorted in L) using the Quicksort algorithm. Wh<strong>at</strong> is the averagecasetime complexity for each of the following code fragments?(a) for (i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!