I want to find the median of a sequence of n integers. To make things simple for this exercise, the integers are distinct and there is an
odd number of them. For instance, the median of
10, 4, 1, 3, 8, 21, 7
is 7.
Of the suggestions below, what's a correct way of doing this?
Select one:
O a. Mergesort the input and report the element in the middle of the resulting sequence.
O b. Use two stacks for odd and even elements, respectively. Report the stacktop of the even stack.
O c. Compute the average (add the elements using a linear scan, divide by their number) and round to the nearest integer.
O d. Insert into a heap $pq$ and return the element at position $pq[(n-1)/2]$.
O e. Hash the elements (assuming constant lookup time) and report the key with the most collisions.
O f. Shuffle the input in linear time, partition once by the first element in the shuffled list, and report the maximum of the left
part.