lec14-algorithms

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

• Notes
• 9

This preview shows pages 1–5. Sign up to view the full content.

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

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

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
14.2 Search Algorithms 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 := ( + r ) / 2 . (b) If x > A [ i ] then := i ; else r := i . February 20 Algorithms and growth of functions, Page 3

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

14.2 Search Algorithms 3. If x = A [ r ] then return( r ); else return( n ).
This is the end of the preview. Sign up to access the rest of the document.
• Winter '07
• YaoyunShi

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern