# MA22S6 Assignment 7 - sorting and the median Mike Peardon ( ```MA22S6
Assignment 7 - sorting and the median
Mike Peardon (mjp@maths.tcd.ie)
March 8, 2012
Answer all four parts. Each part is worth five marks. Hand the homework in by the end of next
Friday’s tutorial (16th March).
Question 1
Draw a picture of the changes to a computer’s memory when the following sequence of five numbers
is bubblesort-ed:
Ω1 = [5, 2, 1, 8, 3]
How many “swap” operations were carried out?
Question 2
Show the steps in a quicksort of the following sequence of ten numbers:
Ω2 = [7, 12, 14, 6, 1, 11, 5, 2, 8]
Choose the pivots at random.
Question 3
On average, the quicksort algorithm takes O (n log2 n) operations to sort n numbers. Describe a
“worst case” initial state and a set of pivots for n numbers that would require O (n 2 ) operations.
Question 4
For a random number X drawn from the distribution
&frac12;
8x
0 ≤ x &lt; 41
f X (x) = 8
(1 − x) 14 ≤ x &lt; 1
3
evaluate:
1. The expected value of X
2. The expected value of the median of a large sample of X values
```