SUNY Geneseo Department of Computer Science


Correctness of Binary Search

{Date}

CSci 141, Spring 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Return tests

Questions?

Binary Search

[Search for x in the Section of Array A between Positions "low" and "high"]

    boolean search( A, x, low, high )
        if ( low <= high )
            mid = (low + high) / 2
            if ( A[mid] < x )
                return search( A, x, mid+1, high )
            else if ( A[mid] > x )
                return search( A, x, low, mid-1 )
            else
                return true
        else
            return false

Correctness

Efficiency

Next

Finish efficiency analysis of Binary Search

Read Section 9.2.2 of text as follow-up to discussion above re what needs to be counted to analyze execution time.


Next Lecture