lec14-algorithms - EECS 203, Winter 2007 Discrete...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
EECS 203, Winter 2007 Discrete Mathematics Lecture 14 Algorithms and growth of functions February 20 Reading: Rosen [3.1, 3.2] February 20 Algorithms and growth of functions, Page 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14.1 Algorithms Algorithms: a sequence of instructions for performing a computation task. Example: Find the maximum. Input: an array of n integers A . Output: max = max { a 1 , ··· , a n } . max( A ) 1. max := A [0]. 2. For i = 1 to n - 1 (a) if max < A [ i ] then max := A [ i ] February 20 Algorithms and growth of functions, Page 2
Background image of page 2
Linear Search Input: an array A of n integers; an integer a . Output: an i such that A [ i ] = a or n if no such i exists. Binary Search Input: an array of n integers A such that A [0] A [1] ≤ ··· ≤ A [ n - 1]; an integer x . Output: an i with A [ i ] = x or n if no such i exists. Binary Search ( A, x ) 1. ` := 0, r := n - 1. the left and right markers for the answer 2. While ` < r (a) i := d ( ` + r ) / 2 e . (b) If
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/01/2008 for the course EECS 203 taught by Professor Yaoyunshi during the Winter '07 term at University of Michigan.

Page1 / 9

lec14-algorithms - EECS 203, Winter 2007 Discrete...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online