This is a good exercise, but you can't enforce people to do a binary search in a programming competition unless you can find a way to identify a search done with a binary search uniquely.
Maybe requiring that the sequence of midpoints until a key is retrieved is returned as part of the solution. It would make it harder to "cheat".
You can add the incrementation of the number of iterations in your algorithm's description and test its exact value in the test suite.
Very interesting problem, thanks!
I would like to know if anyone else is getting a discrepancy in tests 5 and 6. My number of iterations is one less than the expected in those two test sets. I had to start my iteration counter with 2 to get the expected results.
@Jose, it's not a discrepancy, that is how one is suppose to calculate the number of iterations for this problem, as you can see from the example in the problem description.
Find the treasures in MATLAB Central and discover how the community can help you!
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office