edited by
5,739 views
3 votes
3 votes
suppose there are 4 sorted lists of n/4 elements each. if we merge these list into a single sorted list of n elements, for the n=400 number of key comparisons in the worst case using an efficient algorithm is
edited by

3 Answers

Best answer
23 votes
23 votes
There are 4 sorted list each of size 100, as n=400
f1 = 100 records
f2 = 100 records
f3 = 100 records
f4 = 100 records

Combining f1 and f2 needs 100 + 100 - 1 = 199 comparisons, in worst case.
Combining f3 and f4 needs 100 + 100 - 1 = 199 comparisons, in worst case.

 Now we have two sorted & merged files each of size 200, hence we need 200 + 200 -1 = 399 comparisons to merge these files into one file of size 400.

hence total comparisons are required : 2*199 + 399 = 398 + 399 = 797

Note that using MERGE procedure, if there are two files, one with m records, and second with n records, need m+n-1 comparisons in worst case.
selected
0 votes
0 votes
Combining 1 and 2 needs 100 - 1 = 99 comparisons  in worst case.
Combining 3 and 4 needs 100 - 1 = 99 comparisons  in worst case.

 So we have two sorted  merged files each of size 200, so we need 200  -1 = 199 comparisons to merge

 total comparisons : 2*99 + 199 = 397

Using merge function.

Related questions

2 votes
2 votes
1 answer
1
2 votes
2 votes
2 answers
2
0 votes
0 votes
2 answers
3
dhruba asked Jun 5, 2023
1,151 views
Binary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ m < n). ...
1 votes
1 votes
1 answer
4
Tuhin Dutta asked Dec 13, 2017
1,269 views
In a sorted array, every element is repeated more than once except one. what will be the time complexity to find that element in the worst case?