Consider the problem of computing min-max in an unsorted array where m...
When Divide and Conquer is used to find the minimum-maximum element in an array, Recurrence relation for the number of comparisons is
T(n) = 2T(n/2) + 2 where 2 is for comparing the minimums as well the maximums of the left and right subarrays
On solving, T(n) = 1.5n – 2.
While doing linear scan, it would take 2*(n-1) comparisons in the worst case to find both minimum as well maximum in one pass.
Correct answer is (B)
View all questions of this test
Consider the problem of computing min-max in an unsorted array where m...
Explanation:
Algorithm A1 can compute min-max in a1 comparisons without divide and conquer. Let the array be A[1…n]. The algorithm processes the array in a loop of size n/2 (for odd n, last element is ignored). In each iteration of loop, two elements are compared and the smaller element is compared with the current min value and the larger element is compared with the current max value. Therefore, the total number of comparisons in the worst case scenario is (3n/2)-2.
Algorithm A2 can compute min-max in a2 comparisons by scanning the array linearly. The algorithm initializes the min and max values as the first element of the array. It then compares each element of the array with the current min and max values, updating them accordingly. Therefore, the total number of comparisons in the worst case scenario is 2(n-1).
Relation between a1 and a2:
In the worst case scenario, n is even and both algorithms have to process n/2 pairs of elements. Therefore, we can compare the number of comparisons required by both algorithms for a single pair of elements.
Algorithm A1 requires 3 comparisons (2 comparisons for comparison between two elements and 1 comparison for updating min and max values).
Algorithm A2 requires 2 comparisons (1 comparison for comparison between two elements and 1 comparison for updating min and max values).
Therefore, a1 = 3(n/2) and a2 = 2(n-1).
Now, we can compare a1 and a2 as follows:
a1/a2 = (3n/2)/(2n-2) = (3/2)/(2-(2/n))
As n approaches infinity, the denominator approaches 2 and the ratio approaches 3/4. Therefore, in the worst case scenario, a1 is approximately 3/4 times a2.
Answer:
The relation between a1 and a2 considering the worst case scenarios is a1 is approximately 3/4 times a2, which is option B.
To make sure you are not studying endlessly, EduRev has designed Computer Science Engineering (CSE) study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Computer Science Engineering (CSE).