What happens even if a key is not present in the list during a linear search?
What happens even if a key is not present in the list during a linear search?
Solution
In a linear search, each element is compared with the key one by one from the start. If the key is not in the list, no comparison ever succeeds, so the algorithm checks every element up to the last one. Only then does it report that the key is not found (for example, by returning -1 or "not found").
Option 1: the algorithm stops midway only when the key is found, not when it is absent.
Option 2: linear search never skips elements. Skipping is a feature of other methods such as jump search.
Option 3: an absent key is a normal outcome and gives a "not found" result, not an error.
Related questions:
2026: 18 May Shift 2
2026: 23 May Shift 2
2025: 3 June Shift 2
2026: 23 May Shift 1