Match List-I with List-II
List-I List-II (Algorithm) (Recurrence relation) (A).Binary Search (I). $T(n)= T(n/2) + c$ (where $c$ is a constant) (B).Merge Sort (II). $T(n)= 2T(n/2) + \Theta (n)$ (C). Quick sort (worst case partitioning) (III). $T(n)= T(n-1) + \Theta (n)$ (D). Linear Search (IV). $T(n)= T(n-1) + c$ (where $c$ is a constant)
Choose the correct answer from the options given below:
This solution explains how to match common algorithms like Binary Search, Merge Sort, Quick Sort, and Linear Search with their respective recurrence relations. Understanding these relations is crucial for analyzing the time complexity of algorithms.
A recurrence relation defines a function in terms of itself, often used to describe the time complexity of recursive algorithms. Let's analyze each algorithm:
Binary Search works by repeatedly dividing the search interval in half. If the search value is less than the middle element, the search continues in the lower half; otherwise, it continues in the upper half. This process reduces the problem size by half in each step. The work done at each step (comparison and index calculation) is constant. Therefore, the recurrence relation is:
$T(n) = T(n/2) + \Theta(1)$
This matches relation (I): $T(n)= T(n/2) + c$ (where $c$ is a constant).
Merge Sort is a divide-and-conquer algorithm. It divides the input array into two halves, recursively sorts each half, and then merges the two sorted halves. The dividing step takes constant time. The sorting of two halves takes $2T(n/2)$ time. The merging step requires iterating through both halves, which takes linear time, $\Theta(n)$. So, the recurrence relation is:
$T(n) = 2T(n/2) + \Theta(n)$
This matches relation (II): $T(n)= 2T(n/2) + \Theta (n)$.
In the worst-case scenario for Quick Sort, the pivot selection consistently results in one subproblem containing $n-1$ elements and the other containing $0$ elements. This typically happens when the array is already sorted or reverse-sorted, and the first or last element is chosen as the pivot. The partitioning step still takes linear time, $\Theta(n)$. Thus, the recurrence relation becomes:
$T(n) = T(n-1) + T(0) + \Theta(n)$
Since $T(0)$ is a constant, this simplifies to:
$T(n) = T(n-1) + \Theta(n)$
This matches relation (III): $T(n)= T(n-1) + \Theta (n)$.
Linear Search checks each element of a list sequentially until the target element is found or the list ends. If we consider a recursive implementation, it checks the first element. If it's not the target, it recursively searches the remaining $n-1$ elements. The check takes constant time, $\Theta(1)$. The recurrence relation is:
$T(n) = T(n-1) + \Theta(1)$
This matches relation (IV): $T(n)= T(n-1) + c$ (where $c$ is a constant).
Here is a summary table showing the correct matches between the algorithms and their recurrence relations:
| Algorithm | List-I Identifier | Recurrence Relation | List-II Identifier |
|---|---|---|---|
| Binary Search | (A) | $T(n)= T(n/2) + c$ | (I) |
| Merge Sort | (B) | $T(n)= 2T(n/2) + \Theta (n)$ | (II) |
| Quick Sort (worst case) | (C) | $T(n)= T(n-1) + \Theta (n)$ | (III) |
| Linear Search | (D) | $T(n)= T(n-1) + c$ | (IV) |
Based on the analysis, the correct matching is:
This corresponds to Option 1.