Describe how a binary search algorithm works and why it is more efficient than a linear search for large, sorted lists.
Instructor solution
A binary search algorithm works by repeatedly dividing a sorted list in half to locate a target value. It starts by comparing the target value to the middle element of the list. If the target is equal to the middle element, the search is complete. If the target is less than the middle element, the search continues in the lower half of the list; if greater, it continues in the upper half. This process is repeated until the target is found or the sublist is empty. Binary search is more efficient than linear search for large, sorted lists because it reduces the search space by half with each step, resulting in a time complexity of
You may exit out of this review and return later without penalty.