Searching Algorithms Visualizer
← Back to Home
Controls
Select Algorithm:
Linear Search
Binary Search
Array Length:
Or Enter Array (comma separated):
Target Value:
Auto-generate array
Generate Array
Start Search
Current Array:
Linear Search Algorithm
Steps:
Start from the first element of the array.
Compare the current element with the target element.
If the current element matches the target, return its index.
If not, move to the next element.
Repeat until the element is found or the array ends.
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:
Start with the entire sorted array as your search range.
Find the middle index of the current range.
If the middle element equals the target, return its index.
If the target is smaller than the middle element, narrow the range to the left half.
If the target is larger than the middle element, narrow the range to the right half.
Repeat steps 2–5 until the target is found or the range becomes empty.
If the range is empty, return -1 (element not found).
Time Complexity:
O(log n)
Space Complexity:
O(1)
Visualization