The number of comparison steps needed to merge the ascending

The number of comparison steps needed to merge the ascending list –1, 3, 7, 10, 12, 15 with the ascending list –4, –3, –1, 2 is
A 2
B 4
C 5
D 7
The number of comparison steps needed to merge the ascending list –1, 3, 7, 10, 12, 15 with the ascending list –4, –3, –1, 2 is
A 2
B 4
C 5
D 7

Solution

First Comparison

-1 from the first list and -4 from the second list

Hence the first entry will be -4

Second Comparison

-1 from the first list and -3 from the second list

Hence the second entry will be -3

Third Comparison

-1 from the first list and -1 from the second list

Hence the third entry will be -1 *(from the second list)

Fourth Comparison

-1 from the first list and 2 from the second list

Hence the fourth entry will be -1 (from the first list)

Fifth Comparison

3 from the first list and 2 from the second list

Hence the fifth entry will be 2 (from the second list)

Since now the second list is completely exhausted we can copy the remaining elements of the first list directly

Hence there are total 5 comparisons in the worst, therefore correct answer is Option C

 The number of comparison steps needed to merge the ascending list –1, 3, 7, 10, 12, 15 with the ascending list –4, –3, –1, 2 is A 2 B 4 C 5 D 7 The number of c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site