2. You can actually find the median by running a sortingalgorithm and stopping early, as soon as you know the median.
(a) Assume you use Bubble Sort to find the median of 13 elements(i.e. n = 13), but stop as soon as you know the median. Exactly howmany comparisons do you use (in the worst case)?
(b) Assume you use Mergesort to find the median of 13 elements(i.e. n = 13), but stop as soon as you know the median. Exactly howmany comparisons do you use (in the worst case)?
Solution
For Bubble sort, Worst case occurs when array is reversesorted.
In bubble
OR
OR