AlgoMotion

Binary Search Visualizer

Binary Search is an efficient algorithm for finding an item from a sorted list of items. It works by repeatedly dividing in half the portion of the list that could contain the item, until you've narrowed down the possible locations to just one.

2
5
7
8
11
12
15
18
22
25
Speed:
Step: 1 / 12
Binary Search Details

Current Step:

Initial state: Searching for 15 in the array. Low is 0, High is 9.

Pseudocode:

function binarySearch(A, target):  low = 0  high = length(A) - 1  while low <= high:    mid = floor((low + high) / 2)    if A[mid] == target:      return mid  // Found    else if A[mid] < target:      low = mid + 1    else:      high = mid - 1  return -1 // Not found