in Algorithms retagged by
43,430 views
19 votes
19 votes

The minimum number of comparisons required to sort 5 elements is -

  1. 4
  2. 5
  3. 6
  4. 7
in Algorithms retagged by
43.4k views

1 comment

If we apply tournament method to sort 5 elements then,

1.5n-1.5

1.5(5) - 1.5 = 6

Is this approach correct ?
0
0

7 Answers

25 votes
25 votes
Best answer

Minimum number of comparisons = ⌈ log (n!)⌉ = log(5!) =log(120) = 7

Ref:http://en.wikipedia.org/wiki/Comparison_sort#Number_of_comparisons_required_to_sort_a_list

selected by

4 Comments

Ans is 4 when u take base 10
0
0

That is Sterling's approximation. 

This is actual conversion:

log 2 ⁡ ( n ! ) = n log 2 ⁡ n − ( log 2 ⁡ e ) n + O ( log ⁡ n ) = Ω ( n log 2 ⁡ n ) .

3
3
3 votes
3 votes

minimum number of comparison is= log(n!)

so, ceil(log(n!))= ceil(log(nn

=>ceil(log(nn))= ceil(nlog(n))

=>ceil(5log(5))= 4 which is option a

by
1 vote
1 vote
Answer Should Be 4.

this is a best case(Sorted Array) of insertion sort.

Comparisons =n-1.[Best Case of Insertion Sort]

2 Comments

Minimum number of cases are possible in the best case and that will be when it is already sorted and we are using insertion sort. This will take n-1 comparisons. If you find my understanding incorrect then please reply.
0
0
No its wrong. For min number we will look at the worst case.
2
2
1 vote
1 vote

consider a discrete variate x which implies the number of elements in the array. Now either the elements can either be sorted or unsorted, hence probablity is ½

x=     1     2      3       4        5

p=    ½    ½     ½      ½        ½  

hence expected mean or expected number of comparisons=   1(1/2) +2(1/2)  + 3(1/2)   + 4(1/2) + 4(1/2)     = 7(approx)

Thus around 7 comparisons required