SUNY Geneseo Department of Computer Science


Execution Time of Binary Search

{Date}

CSci 141, Spring 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Hand out Homework 2

Questions?

Binary Search

    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

Efficiency

How to express efficiency - Section 9.2.2

[Functions that Do or Don't Grow Proportionally to b(n)]

Best case: find x in middle of section

Worst case

[Remove One of n Elements (Middle), Divide Remaining n-1 in Half]

[Closed Form Can Sample True Function]

Next

Introduction to lists

Read Section 11.1 through Section 11.3.1


Next Lecture