in Algorithms retagged by
545 views
1 vote
1 vote

 

in Algorithms retagged by
by
545 views

4 Comments

(C) nlogn/2 ??
0
0
Yes Please Explain
0
0

C. 

At every level, in best case, n/2n/2 comparisons and total lognlogn levels...Hence, nlogn/2

0
0

2 Answers

1 vote
1 vote
Best answer

2-way bottom-up merge sort the last level (except original array) named as level-1, so on... and let n=2k ===> only k levels present totally

if two sorted arrays have n1 and n2 elements ===> to merge them we require no.of comparissions

1) minimum = n1 

2) maximum = n1+n2-1

minimum no.of comparissions required for forming

level 1 :- $\frac{n}{2^{1}} $ . 1

level 2 :- $\frac{n}{2^{2}} $ . 2

level 3 :- $\frac{n}{2^{3}} $ . 4

.

.

.

.

 

level j :- $\frac{n}{2^{j}} $ . 2 j-1

 

Total Comparissions = $\sum_{j=1}^{k} \frac{n}{2^{j}}.2^{j-1}$ = $ \sum_{j=1}^{k} \frac{n}{2} $ = $  \frac{n}{2} \sum_{j=1}^{k} 1 $  = $  \frac{n}{2} (k) $ = $  \frac{n.log(n)}{2} $

selected by
1 vote
1 vote
when all the elements are in increasing order(1,2,3,4,5......n)

lets take example 1, 2, 3, 4, 5, 6, 7, 8  it only requires 12 comparisons.

in 1st level 1+1+1+1 = 4 comparisons

in 2nd level 2+2 = 4 comparisons

in 3rd level 4 comparisons

total 4+4+4 =12 comparisons which is (nlogn/2) C option.

Related questions

1 vote
1 vote
0 answers
3