Here’s the invariant for partition
again:
and here’s the pseudocode:
void partition(A, start, end)
, j
initialize i
choose pivot[start]
swap pivot to Awhile [?] section != []
[i]:
# process Aif <= p:
<= p section
grow else:
> p section grow
Write more detailed pseudcode for the if/else
block inside the while
loop. What needs to be done, in terms of elements and indices in A
, to grow one section or the other?
How could you choose a pivot that would guarantee a total of O(log n) levels of partitioning? Why isn’t this a good idea?
Run insertion sort on the following input array, sorting on only the digit value. Is insertion sort stable?
Run selection sort on the same input array above, sorting on only the digit value. Is selection sort stable?
Which of the four sorting algorithms we’ve covered are in-place?
Is merge sort stable?
Is quicksort (as presented in lecture) stable?
What is the space complexity of quicksort?