29 55 43 12 31
(a) List all of the inversions in this list.
(b) Perform a series of adjacent swaps one at a time to get the list in sorted order. Show the resulting list after each adjacent swap.
(a) Show the array after BuildHeap()
is applied to it
(assume that there is no sentinel value used -- i.e., 29 is the
root node before BuildHeap()
is run).
(b) Show the array after each step of the sort takes place (i.e., after each delete operation).
n-1, 1
. Use the integers
1-7 without repeating any value. In one sentence explain why it's a
worst case.1 2 3
4
" would be "2
"). In one sentence, explain why
this input is a worst-case.(a) Write a recurrence relation expressing the running time of recursive binary search.
(b) Solve the recurrence relation using repeated substition or telescoping to prove its O(logn) running time. Be sure to show all your work.
(c) Write a recurrence relation expressing the running time of recursive linear search.
(d) Solve the recurrence relation to prove its O(n) running time.
(a) Explain to the CEO why this decision may be unwise, and suggest a better official sorting algorithm.
(b) Annoyed by your failure to mindlessly accept corporate policy, the CEO says that s/he will accept your suggestion for the official sorting algorithm if you can make it run in O(n) time whenever it gets an input that would have been a best case for Insertion Sort. Your change must not asymptotically affect the running time for other inputs. Briefly describe a simple change you could make to your suggestion for part (a) that would meet the CEO's goal (hint: there is a simple solution that works regardless of your choice of algorithm in part (a)).