$ cd $ cd cs21/inclass $ pwd /home/your_user_name/cs21/inclass $ mkdir w08-search $ cd w08-search $ pwd /home/your_user_name/cs21/inclass/w08-search $ cp ~adanner/public/cs21/w08-search/* . $ ls
We've seen that we can use import to add extra functionality to our python programs. Examples are from math import *, from graphics import * or from random import randrange. We can also import functions from code we write. For example we could have a file called search.py that wants to import code from goodwords.py. We can add from goodwords import * to the top of search.py if goodwords.py is in the same directory as search.py.
Now note that goodwords.py has some test code. When we run python goodwords.py we want to run this test code to see if goodwords.py works. However, when we import goodwords we may want to run different tests and not the ones in goodwords.py. The line if __name__ == "__main__": allows us to control this behavior. When we run python goodwords.py, the expression evaluates to True, but when we use import the expression evaluates to False in goodwords.py.
Under what conditions can a computer algorithmically search for and find information? What is the minimum set of input? What is the format of the input? What are the possible outcomes? How can a computer express thouse outcomes in output? Finally, what steps should a computer take to perform this task and how do the number of steps needed depend on the size of the input?
We will discuss two searching methods: linear search and binary search.
Open search.py in vim.
What should the search functions return? Let's describe linear search, implement it, test it, and analyze its run-time together. What is the minimum number of steps required? What is the maximum number of steps? What constitutes a step?