Question:

What is the worst-case scenario for a linear search in an array of 'n' elements?

Show Hint

In Linear Search, the worst-case complexity is $O(n)$ because we must traverse the entire array to find the target if it is at the very end or absent!
Updated On: Jun 11, 2026
  • The target element is the last element
  • The target element is the first element
  • The array is sorted
  • The array is unsorted
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Question:

The question asks to identify the worst-case scenario for running a Linear Search algorithm on a database array consisting of $n$ elements.

Step 2: Linear Search Comparisons:

- Linear search compares the target element with each element of the array sequentially, starting from index 0.
- The number of steps depends directly on the location of the target value.

Step 3: Detailed Explanation of Scenarios:

- Let us evaluate each scenario:
- Best Case: The target element is found at the first position index 0. The search ends after exactly 1 comparison.
- Average Case: The target is somewhere in the middle of the array, requiring approximately $n/2$ comparisons.
- Worst Case: The target is located at the very last index of the array ($n-1$), or it does not exist in the collection at all. In both cases, the algorithm is forced to compare the target with all $n$ elements in the array. This requires $n$ comparison operations.
- Among the options, "The target element is the last element" represents this worst-case scenario of $n$ comparisons.

Step 4: Final Answer:

The worst-case scenario for a linear search is when the target element is the last element of the array.
Hence, option (A) is the correct choice.
Was this answer helpful?
0
0