Skip to main content
PreparationZone Logo
PreparationZone
Back to Fundamentals

Fundamentals · Easy · Free

When is linear search acceptable in production systems?

FresherFundamentalsData Structures & Algorithms
Model answer

When linear search is OK

Scan each element until match—O(n). Acceptable when data is unsorted, tiny (n < ~50), or only one lookup and sorting cost dominates.

  • Linked list without index—must walk nodes.
  • Small in-memory config lists, feature flags.
  • Hardware / embedded tables where n is bounded.
java
int linearSearch(int[] a, int x) {
  for (int i = 0; i < a.length; i++) if (a[i] == x) return i;
  return -1;
}
Production systems combine: hash index for hot keys, linear for rare cold paths.