retagged by
551 views

2 Answers

2 votes
2 votes

The answer would be $36$ .

Question asks for number of comparisons, it neither specifies maximum or minimum. Neither it specifies sorting technique nor it specifies whether we need to sort ascending or descending. In such case there are just so many answers.

For sorting such as Bubble Sort , Selection Sort we would take fixed $\frac {n\times(n-1)}{2} $ comparisons for both ascending or descending sequence, that gives answer $36$

Merge Sort would give least number of maximum comparisons for general cases ,and would be same irrespective of ascending or descending, and it would be at most $(n\left \lceil log_2(n) \right \rceil- 2^{\left \lceil log_2(n) \right \rceil} +1 )$.

For this question merge sort takes $21$ comparisons.

and then there is Insertion Sort which takes $d+(n-1)$ comparisons, where $d$ is number of inversions.

Two elements $a[i]$ and $a[j]$ form an inversion if $i < j$  and $a[i] > a[j]$ 

In word ALGORITHM there are $12$ inversions, hence for ascending  $ 12+8=20$ comparisons

and for descending $\frac {n\times(n-1)}{2} -12+8=24+8=32$ comparisons

edited by
0 votes
0 votes

On using the merge sort technique, the number of comparisons required to sort n elements is n-1

In ALGORITHM we have 9 letters so we need 8 comparisons 

Related questions

0 votes
0 votes
0 answers
4