Searching Algorithms

Explore how different searching algorithms find elements in a sorted array.

Algorithm Information

Linear Search

Linear search is the simplest searching algorithm that checks each element in the array sequentially until the target element is found or the end of the array is reached.

Time Complexity

O(n) - where n is the number of elements in the array

Space Complexity

O(1) - constant space required regardless of input size

When to Use

  • When the array is small
  • When the array is unsorted
  • When simplicity is preferred over efficiency

Comparison of Search Algorithms

AlgorithmTime ComplexitySpace ComplexityRequires Sorted ArrayBest For
Linear SearchO(n)O(1)NoSmall or unsorted arrays
Binary SearchO(log n)O(1)YesLarge sorted arrays
Jump SearchO(√n)O(1)YesMedium-sized sorted arrays
Interpolation SearchO(log log n) to O(n)O(1)YesUniformly distributed sorted arrays
Exponential SearchO(log n)O(1)YesUnbounded/infinite arrays