1 One Way Find Median List Sort List Take Middle Element Assume Use Bubble Sort Sort List Q37095305

1. One way to find the median of a list is to sort the list andthen take the middle element.

(a) Assume you use Bubble Sort to sort a list with 13 elements(i.e. n = 13). Exactly how many comparisons do you use (in theworst case)?

(b) Assume you use Mergesort to sort a list with 13 elements(i.e. n = 13). Exactly how many comparisons do you use (in theworst case)?


Answer


A)

Bubble sort needs 78 comparisons to sort the array of 13elements in worst case.

for(i = 0; i < n; i++)
{
for(j = 0; j < n-i-1; j++)
{}

}

here comparision are n-1+n-2+n-3……….1

here for

OR
OR

Leave a Comment

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