01:198:107 Lecture Notes - Lecture 13: Linear Search, Binary Search Algorithm

88 views3 pages

Document Summary

In an ordered array, one test can rule out a whole region of the array. Low: lowest index where the target might be. High: highest index where the target might be. Mid: where to look next, average of high and low. % assumes vector is in increasing order. % returns index j such that vector(j)==target. % returns 0 if target not in vector. To search a sorted array of length n, At most log(n) elements need to be looked at. For a large array binary search is faster than linear search. Not if the target is in the first element of the vector. We would like to make general statements about one algorithm being faster than another. Binary search is faster than linear search. There are too many variables to use variables to use actual time to compare algorithms. Count should model work done by algorithm. Problem: number of operations depends on size of input.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents