# Lab: Searching

Summary: In this laboratory, we explore different issues related to searching.

Contents:

## Exercises

### Exercise 0: Preparation

a. Start DrScheme.

b. If you have not done so already, please scan the reading on searching. In particular, you should look at the sample procedures. Make sure that you understand the purpose of `get-key` in `binary-search`.

d. Create a vector, `names`, of a dozen or so lists, each of which contains a last name and a first name. Order the list by last name.

### Exercise 1: Testing Our Procedures

a. Using `sequential-search-list`, search for the letter `#\a` in various lists of characters.

Note that it's probably easiest to create a list of characters with `string->list`.

b. Using `sequential-search-vector`, search for the letter `#\a` in various vectors of characters.

c. Develop some tests for `search-list-for-keyed-value`. For example, you might create a list of cartoon characters and their sidekicks and search the list for character or sidekick.

### Exercise 2: Extending sequential-search-vector

Write a procedure that takes a predicate and vector as parameters and, using `sequential-search-vector` as a helper, finds a value in the vector that matches the predicate or returns #f if no such value exists. (Like `sequential-search-vector`, this procedure searches vectors; unlike `sequential-search-vector` and like `sequential-search-list`, this procedure returns a matching value, rather than an index.

### Exercise 3: Observing Binary Search

Add calls to `display` and `newline` to the definition of `binary-search`, so that it prints out the values of `lower-bound` and `upper-bound` each time the kernel procedure is called. How many recursive calls are made as binary search finds your name in the list `names`? How many are made in an unsuccessful search?

## History

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Tue May 6 09:20:02 2003.
The source to the document was last modified on Mon Feb 24 22:31:42 2003.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2003S/Labs/searching.html`.

You may wish to validate this document's HTML ; ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu