Quicksort and Mergesort Exercises
Consider the following array of integers a:
0 1 2 3 4 5 6 7 8 9 (index)
______________________________
| |
| 6 2 7 1 9 8 5 3 4 0 |(value)
|______________________________|
- Quicksort
- Show the array after the first call to partition.
- The original call to the qsort method would be qsort(a,0,9).
Show the recursive calls that are made directly from this
initial call to qsort, and the calls that are made directly from each of
those calls. You can refer to the array simply as a.
- Mergesort
- Show a stack with the first 8 calls to Mergesort. As above, you
can refer to the array simply as a. Cross off
completed calls as we did in class.
- If the merging operation were done by a separate method
merge(a, lo, hi) (as in the pseudocode
we gave in class -- assume that merge will calculate the midpoint
itself), show what calls to merge would appear in the above stack.