2 Actually Find Median Running Sorting Algorithm Stopping Early Soon Know Median Assume Us Q37095332

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.