Binary Search

In a nutshell, this search algorithm takes advantage of a collection of elements that is already sorted by ignoring half of the elements after just one comparison.

Pseudo Code Algorithm:

parameter list: a list of sorted value parameter target: the value to search for

if the list has zero length, then return false

determine the slice point: if the list has an even number of elements, the slice point is the number of elements divided by two if the list has an odd number of elements, the slice point is the number of elements minus one divided by two

create an list of the elements from 0 to the slice point, not including the slice point, which is known as the "left half" create an list of the elements from the slice point to the end of the list which is known as the "right half"

if the target is less than the value in the original array at the slice point, then return the binary search of the "left half" and the target

if the target is greater than the value in the original array at the slice point, then return the binary search of the "right half" and the target

if neither of those is true, return true

Binary Search Recursive:

Delete Node

Another:

ArrayBinary Search TreeLinked ListExtra-ArrayStackBinary TreeRecursionHash TableSearchingSortingQueue SandboxHash TableDouble Linked ListGraphsExoticHeap

Last updated

Was this helpful?