What is the recurrence relation for the linear search recursive algorithm?
2025
What is the recurrence relation for the linear search recursive algorithm?
- A.
T(n-2)+c
- B.
2T(n-1)+c
- C.
T(n-1)+c
- D.
T(n+1)+c
Attempted by 3 students.
Show answer & explanation
Correct answer: C
Concept: For a recursive algorithm, the running-time recurrence T(n) captures two parts: the constant work done at the current call before recursing (one comparison, one bookkeeping step — call this cost c), plus the time taken by the recursive call on whatever sub-problem remains. In general, T(n) = (work at this level) + T(reduced size).
Application (step by step):
Recursive linear search examines exactly one array element per call (e.g. the last element) and compares it with the target — this costs a constant amount of time, c.
If it matches, the call returns immediately; otherwise the function makes exactly one recursive call on the remaining n-1 elements (the array with one element removed from consideration).
So the total time for input size n equals the constant comparison cost c plus the time for the recursive call on size n-1: T(n) = T(n-1) + c.
The base case is T(0) = c (constant, O(1)) when the array is empty.
Cross-check: Solving T(n) = T(n-1) + c by repeated substitution gives T(n) = T(0) + n·c = O(n), matching the well-known linear time complexity of linear search — confirming the recurrence is consistent with the algorithm's known behaviour. This form (reduce-by-one, one recursive call) contrasts with other divide-and-conquer recurrences, shown below:
Algorithm | Recurrence | Resulting complexity |
|---|---|---|
Linear search (this question) | T(n) = T(n-1) + c | O(n) |
Binary search | T(n) = T(n/2) + c | O(log n) |
Merge sort | T(n) = 2T(n/2) + cn | O(n log n) |