Where is linear search used? Among the options given, choose the most complete…

2023

Where is linear search used? Among the options given, choose the most complete one.

  1. A.

    When the list has only a few elements

  2. B.

    When performing a single search in an unordered list

  3. C.

    Used all the time

  4. D.

    When the list has only a few elements and when performing a single search in an unordered list

Attempted by 682 students.

Show answer & explanation

Correct answer: D

Concept

Linear (sequential) search scans elements one by one until the target is found or the list ends. It needs no preprocessing and works on data in any order, but it costs O(n) comparisons. So linear search is the right choice precisely when the one-time O(n) scan is cheaper than paying to prepare a faster structure — that is, when the data is small or when you will search it only once.

Applying the principle

  • Few elements: for a small n, an O(n) scan finishes almost instantly, and building/maintaining a sorted array or hash table is not worth the extra effort. Linear search wins.

  • Single search in an unordered list: a one-off lookup on unsorted data does not justify sorting first, which alone costs O(n log n). One O(n) pass is cheaper than sort-then-search, so linear search wins here too.

Why both, not just one

Each scenario on its own is a standard, textbook use case for linear search, so the answer that names both of them together is the complete and correct one. Choosing only one of the two scenarios leaves out an equally valid case.

Contrast

  • “Used all the time” is false: for large data searched repeatedly, the O(n) cost dominates and sorting once then using binary search (O(log n) per query) or hashing (O(1) average) is far better.

Hence linear search is used both when the list has only a few elements and when performing a single search in an unordered list.

Explore the full course: Coding For Placement