Ana Ramírez Chang
CS 302
Assignment 3

  1. When students learn to write recursive functions, I expect they will have a hard time assuming the recursive function already exists and just using it. This set of excercises would help them break the problem down into sub problems where one of the sub problems will be solved by a call to the recursive function.


    Excercise:
    Write a function that takes a Go board and a position p on the Go board and returns the number of stones in the group that includes the stone at position p. A group of stones is a collection of stones that are all linked together. There are no empty spaces cutting some of the stones off from the rest of the group.

    1. Break the problem into subproblems where one of the sub problems looks like the original problem called with different arguments.
    2. Select the subproblem that will be "implemented" with a black box (the one that looks like the orignial problem).
    3. Implement each sub problem (implement the black box supproblem by giving it a function name without implementing the function).
    4. Implement a function that solves the original problem using the solutions to the sub problems and the black box function.
    5. Rename the main function and the black box function to have the same name.
  2. I expect students coming into the class not to have studeid types formally, and so not to have a clear understanding with them. On the other hand, I expect students to have a good grasp of values from a previous programming class and from their studeis in math. When they learn about types, I expect them to lump them in together with values since values are familiar to them, and types are not as familiar.

    Excercises:

    1. Complete the following table of types and examples of values.
      Type (τ)
      Example of Value (v)
      int
      -7
      -15
      int
      0
      int
      9
      bool
      true
      int
      false

    2. Fill in the type of the following expressions:
      1:___
      true:_____
      (1 + 5):_____
      (true andalso false):____
      (if true then 1 else 5):_____
    3. Fill in the value each expression evaluates to:
      1−> ____
      true−> _____
      (1 + 5)−> _____
      (true andalso false)−> ____
      (if true then 1 else 5)−> _____

  3. I expect students to be used to implementing all the subproblems in a problem. I expect this previous experience may make it hard to abstract and use a "black box function" to implement a subproblem when they implement a solution to a problem with a recursive function.