Searching Algorithms Visualizer

← Back to Home

Controls






Current Array:

Linear Search Algorithm

Steps:

  1. Start from the first element of the array.
  2. Compare the current element with the target element.
  3. If the current element matches the target, return its index.
  4. If not, move to the next element.
  5. Repeat until the element is found or the array ends.
  6. If the element is not found, return -1 (or indicate that it is not present).
Time Complexity: O(n)
Space Complexity: O(1)

Binary Search Algorithm

Steps:

  1. Start with the entire sorted array as your search range.
  2. Find the middle index of the current range.
  3. If the middle element equals the target, return its index.
  4. If the target is smaller than the middle element, narrow the range to the left half.
  5. If the target is larger than the middle element, narrow the range to the right half.
  6. Repeat steps 2–5 until the target is found or the range becomes empty.
  7. If the range is empty, return -1 (element not found).
Time Complexity: O(log n)
Space Complexity: O(1)

Visualization