gear

Discrete Structures Tutorials

Relations Tutorial - Binary Search

by David Muñoz and Will Ptacek

A binary search searches through a sorted array by repeatedly dividing the array in half. If the value of the search term is less than the middle value of the array, then the lesser half becomes the “new array.” If not, then the upper half becomes the “new array.” This is repeatedly done until there are only two values left, at which point the search term is either one of the two values.

As it is more efficient than a linear search, binary searches are commonly used whenever data is sorted.