17,933 views
3 votes
3 votes
The average no. of comparisons performed by the merge sort algorithm, in merging two sorted lists of length 2 is -

a) 8/3

b) 8/5

c) 11/7

d) 11/6

2 Answers

Best answer
7 votes
7 votes

Let's first solve this question with Brute-force approach.

Let $1,2,3,4$ be the four numbers.

So, We have Two sorted lists of $2,2$ item each. So, We have 4C2 = 6  possibilities

$1,2$ and $3,4$  => $2$ comparisons required.

$3,4$ and $1,2$  => $2$ comparisons required.

$1,3$ and $2,4$ =>  $3$ comparisons required.

$2,4$ and $1,3$ =>  $3$ comparisons required.

$1,4$ and $2,3$ =>  $3$ comparisons required.

$2,3$ and $1,4$ =>  $3$ comparisons required.

So, Average number of Comparisons (Expected number of comparisons in a merge step ) = $16/6 = 8/3$


Now, that is Brute-force approach and clearly, it is efficient only for small cases like the one asked.

There is a General formula for Expected number of comparisons in a merge step When Each Sorted array has $n/2$ elements :

Expected number of comparisons in a merge step = $\frac{n^2}{n+2}$ ..Note that $n/2$ is the number of elements in both sorted arrays, Not $n$.

 The expected number of comparisons is pretty close to $n−2$.  As  $\frac{n^2}{n+2}$ $≈$ $n-2$

selected by
0 votes
0 votes
consider 1,2,3,4 is required sorted order. then,

two list can be (i) 1, 2 and 3,4  (ii) 1, 3 and 2,4  (iii) 1, 4 and 2, 3

The number of comparisons needed in each case will be 2, 3, 3 respectively.

& So, average number of comparisons will be (2+3+3)/3= 8/3

Related questions

0 votes
0 votes
0 answers
1
Vikas123 asked Jan 8, 2019
1,038 views
Can anyone help me to understand this problem….??
3 votes
3 votes
1 answer
2
Kaushal Sanadhya asked Oct 9, 2018
1,689 views
How many swaps are performed in Merge sort algorithm in worst case?
0 votes
0 votes
3 answers
3
pradeepchaudhary asked Jul 8, 2018
1,530 views
A list of n string, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is(A) (B) (C) (D)...
0 votes
0 votes
2 answers
4
radha gogia asked Jul 31, 2015
11,575 views
If I have two lists of length 2 then no of comparisons in the worst case would be 2 only , since If I have say 10,20 in list A and 5,7 in list B so then on merging 10 is ...