Lab: Binary Search, Quick sort, Merge Sort


Binary Search


function binary_search(A, n, searchItem)

    L := 0

    R := n − 1

    while L ≤ R do

        m := floor((L + R) / 2)

        if A[m] < searchItem then

            L := m + 1

        else if A[m] > searchItem then

            R := m - 1

        else:

            return m

    return unsuccessful