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.
View all questions of this test
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.
Consider the problem of computing min-max in an unsorted array where m...
Explanation:
Algorithm A1:
- In the worst-case scenario, Algorithm A1 will compare every pair of elements in the array to find the min and max.
- Since there are n elements in the array, the total number of comparisons made by Algorithm A1 will be n*(n-1)/2.
- Therefore, a1 = n*(n-1)/2.
Algorithm A2:
- In the worst-case scenario, Algorithm A2 will scan the array linearly to find the min and max elements.
- It will make 2 comparisons for each pair of elements it encounters while scanning the array.
- Therefore, a2 = 2*(n-1).
Relation between a1 and a2:
- Comparing the two formulas for a1 and a2, we get:
a1 = n*(n-1)/2
a2 = 2*(n-1)
- As n*(n-1)/2 is a quadratic function of n and 2*(n-1) is a linear function of n, in general, the quadratic function will grow faster than the linear function.
- Therefore, in worst-case scenarios, a1 will be greater than a2.
- Hence, the relation between a1 and a2 is a1 > a2.