Given a set of n sorted distinct integers, the average case time complexity to search a key using linear search is
Tripura Public Service Commission - 2026,
Answer: C
The average is (n+1)/2 comparisons.
Assume the key is equally likely to be at any of the n positions. Finding it at position i costs i comparisons, so the average is the mean of 1, 2, ..., n.
\[ \begin{aligned} \text{average} &= \frac{1 + 2 + \cdots + n}{n} \\ &= \frac{n(n+1)}{2n} = \frac{n+1}{2} \end{aligned} \]
n/2 is the rough approximation, and (n-1)/2 undercounts by one. n - 1 is close to the worst case, not the average. Sorting does not help a linear search, which still scans from the start.
Please log in or register to report this question.