Visualize the efficiency of Binary Search. Watch how the search space halves at each step. Perfect for learning divide and conquer.
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.
Set a left pointer at the start and a right pointer at the end of the sorted array.
Calculate the middle index based on left and right pointers.
If the middle element is the target, done. Otherwise narrow the search window left or right.
Repeat the process until the left pointer exceeds the right pointer, meaning the target is not in the array.
Binary Search requires the array to be strictly sorted before execution. It is incredibly efficient for large data sets.