Yup, Ive stated what needs to be done to each function provided.
Main Topics
Browse All TopicsYou should augment both functions to count the number of comparisons each makes.
To test your work, create a sorted list containing the 1000 elements 1..1000. Write code that searches the list for each value between 1 and 1000. Find the average number of comparisons for each of the techniques.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Well, I can lead you towards the solution. However, YOU have to do the steps. My questions:
Firstly, some comment. The identifier 'list' is used for a built-in data type. Nor you and nor your teacher should use 'list' as identifier for a variable. The lst is fine in such situations.
I guess you have found that the binary search requires the sorted list.
Now, you can generate the list simply by range(). For example
lst = range(1, 1001) # is equal to: lst = [1, 2, 3, ..., 999, 1000]
The question says in other words "do search for each element in the list". Now it is clear that you must do it in the loop. I suggest to use the Python for loop here like this. I will write it but I expect you to study it, understand it and write the similar loop without the for loop (using the while). See the snippet below.
The reporting could also be enhanced. The print could be moved from inside the functions. The count value can be passed also in return command.
Business Accounts
Answer for Membership
by: peprPosted on 2009-10-23 at 00:12:48ID: 25641916
Homework? And what is your question? ;)