Search⌘ K
AI Features

Searching Algorithms: Summary

Explore the fundamentals of searching algorithms by examining linear and binary search. Learn how to determine when to use each algorithm based on data characteristics, and understand the performance differences through input size impact and key algorithm features in JavaScript.

Having studied both search algorithms, the table below summarizes their key differences.

Feature

Linear Search

Binary Search

Data requirement

Works on ordered or unordered collections (e.g., arrays, lists)

Requires sorted data in an indexed structure (e.g., arrays, lists)

Time complexity

O(n) in the worst case

O(log n) in the worst case

Space complexity

O(1)

  • O(1) iterative

  • O(log n) recursive

How it works

Checks elements one by one from start to end

Repeatedly divides the search space in half

Best for

Small collections, unsorted data, single lookups

Large sorted collections, repeated lookups

Implementation

Simpler often has a single loop

Slightly more complex, uses variables such as low, high, and mid

...