1 Mutual Recursion
2 Generative Recursion

Problem Set 7

Language: Advanced Student
Due: 11:59 PM Wednesday, Feb. 23

1 Mutual Recursion

Start this problem set by downloading starter code, which contains a helpful components for both exercises. Complete Exercise 15.1.3, but skip count-proper-descendants.

2 Generative Recursion

  1. Using the starter code's guess-with-linear-search function as a model, along with the binary search lecture notes, define the function:

      ; guess-with-binary-search : (integer -> answer) integer integer -> guess-result
      ; Guesses a secret using binary search.
      (define (guess-with-binary-search secret low high) ---)
      
    Note that guess-with-linear-search returns both the number of guesses used and the secret, in a guess-result structure, just as your function should. To count the guesses, you can use the increment-guesses helper function in essentially the same way as in guess-with-linear-search.
    Lastly, to help you test your function, here is a check-expect that tests whether it indeed gets a secret of 50 correct on the first try. You will want to create at least two additional tests:
    (check-expect (guess-with-binary-search (lambda (guess) (check-guess guess 50)) 1 100) (make-guess-result 50 1))

  2. Using the supplied run-game function in the starter code, run your binary search function with make-uniform-secret between 1 and 100, a total of 10000 times. (For help on calling run-game, follow the examples in the starter code). How many guesses are required on average? How does this compare with linear search?
  3. Now try 10000 runs in run-game with your binary search and make-special-secret between 1 and 100. How many guesses are required on average? Try making a small alteration to your binary search function to achieve better performance for special secrets, and report on any improvements you observe.