In this lab you will cover:
2 5 3 8 6 10 6
your algorithm should print
Target value 6 found at position 5 in the list.
If the user inputs the same list, but target vale 4, your algorithm should print
Target value 4 not found in the list.
Before reading the notes or the book, try and come up with a solution on your own and show it to me. It is important to try to do this on your own before before you look at the notes/book.
What is the key idea of your algorithm? Why do you think the algorithm is called sequential search? You do not need to write down the answers, only to think about them.
Now look at the search algorithm in Figure 2.9 in the book. The problem is slightly different, searching for a target name in a list of 10000 input names. However the algorithm is conceptually the same as the one for searching a list of numbers. Work through a couple of examples and understand how the algorithm works.
1. Select the menu item Go -> Connect to Server and type afp://collaboration.bowdoin.edu
2. Enter your personal Bowdoin login (e-mail) Name and Password.
3. A new icon called Computer Science will appear on the desktop.
4. Double-click the folder Computer Science -> csci107
The following folders are particularly useful for completing this and other assignments in this course.
csci107 -> Users -><your username> is a folder in which you can save work from week to week during the semester.
csci107 -> Invitation contains the lab software for many exercises in this course.
csci107 -> Drop Box is the place where you can submit an electronic copy of your completed work when you finish an assignment.
Drag a copy of the folder csci107 -> Invitation to your desktop, and then close the folder csci107.
In this window, select Algorithm -> Search for Value, and then select the Run button. Watch each step execute and the Target value change. You may Reset and Rerun this exercise several times to get a feeling for the relationship between it and the date values.
As you work through the algorithm, think what happens if the target
occurs multiple times in the list. Which occurence would the
algorithm find? How would you modify the algorithm to find, say, the
last, or first, occurence? How would you modify the algorithm to
find all occurences? You do not need to write down the answers, only
to think about them.
Be sure to justify your answers! You may do this work either with a word processor or by hand. If you type your solutions, bring a hard copy of your assignment and hand it in class. If you write by hand, do your best at writing legibly and leave space between problems.
You may choose to do this assignment either by yourself or in a group. However, solutions should be written up individually and handed in on Tuesday, at the beginning of class.
Once you are finished in the lab, if you saved any documents in yout collaboration personal directory, be sure to drag the csci107 icon to the Trash (this step disconnects you from the server and prevents someone else, who may use this iMac later in the day, from accidentally accessing files in your personal folder) and log out!