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
Algorithm | Time Complexity | Space Complexity | Requires Sorted Array | Best For |
---|---|---|---|---|
Linear Search | O(n) | O(1) | No | Small or unsorted arrays |
Binary Search | O(log n) | O(1) | Yes | Large sorted arrays |
Jump Search | O(√n) | O(1) | Yes | Medium-sized sorted arrays |
Interpolation Search | O(log log n) to O(n) | O(1) | Yes | Uniformly distributed sorted arrays |
Exponential Search | O(log n) | O(1) | Yes | Unbounded/infinite arrays |