[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Outlines] [Labs] [Assignments] [Quizzes] [Questions] [Exams] [Examples]
Back to Analyzing Algorithms. On to Sorting.
Held Tuesday, February 8, 2000
Overview
Today we consider the problem of searching: given a collection of values with ``keys'', find an item with a designated key.
Question 10 for today's class: Explain unambiguously how to look up a phone number in a phone book given the person's name. Also describe how to look up a person's name in the phone book given their phone number.
Question 11 for Wednesday's class: Describe how to put a pile of books in alphabetical order by author.
Notes
Contents
Summary
A[i] for the ith element of
array A.
To look up the name for phone number p in phonebook B
1. For each record, r, in B
a. If r.number equals p then
i. Set answer to r.name
ii. Don't look at other records
2. If answer has a value then
a. Return that value
3. Otherwise
a. Indicate that no one has that phone number
boolean binarySearch(Element element, Collection stuff)
While there are usable elements in stuff
Identify mid, the middle usable element
If element equals mid then
Return true
Else if element < mid then
Throw away all elements greater than mid
Else
Throw away all elements less than mid
boolean binarySearch(Element element, Collection stuff)
If stuff is empty then return false
Identify mid, the middle element of stuff
If element equals mid then
Return true
Else if element < mid then
Let smaller be the elements of stuff smaller than mid
Return binarySearch(element, smaller)
Else // element > mid
Let bigger be the elements of stuff larger than mid
Return binarySearch(element, bigger)
Saturday, 22 January 2000
Tuesday, 8 February 2000
Back to Analyzing Algorithms. On to Sorting.
[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Outlines] [Labs] [Assignments] [Quizzes] [Questions] [Exams] [Examples]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS105/2000S/Outlines/outline.10.html
Source text last modified Tue Feb 8 09:34:18 2000.
This page generated on Tue Feb 8 09:33:21 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu