01:198:111 Lecture Notes - Lecture 2: Vending Machine, Infinite Loop

198 views4 pages
Verified Note

Document Summary

Sequential programs - algorithms are done in order one at a time. Parallel programs - algorithms are done in tandem with another program. Algorithm for finding a number in a sorted list, e. g. 10, 20, 25, 30, 35, 40, 45, 50, target. Takes the number and compares to each term sequentially until the number matches. Can write an if statement, where the program stops searching once the number on the list is >38. Worst case: target is the last term. Takes a middle term, e. g. 40, and compares 38 with it. Then it determines if 38 is below or above 40, and takes another middle term in the lower half and compares 38 to it. Rinse and repeat until target is found or is shown not to exist. Efficient, since even in a list with 10^6 terms, it only takes at most 20 searches to find the correct answer. Assume the machine takes only 25 cent coins.

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