A binary search program in Python
We have now worked through two explanations of how binary searching works. It's time to write some code!
Q1. Type in the following code and get it working. This code generates a list of random numbers and provides a function for printing out. We know binary searching won't work unless the data is sorted so we use one of our previous sorting algorithms to sort the data. We then have the code for the binary search.
Q2. If you had to test the code thoroughly, what tests would you carry out? Write a list of the sorts of tests you ought to do, identify any test data you will use, predict the results of each test and then carry them out.