CMPSCI 250: Introduction to Computation

Second Midterm Exam

David Mix Barrington

3 April 2012

Directions:

  Q1: 35 points
  Q2: 25+10 points
  Q3: 40 points
Total: 100+10 points

Here are several definitions used on the exam.

Remember that natural always means "non-negative integer".

Generalized Fibonacci Numbers:: If a and b are any two naturals, we define the function Ga,b by the rules (1) Ga,b(0) = a, (2) Ga,b(1) = b, and (3) (for n ≥ 1) Ga,b(n+1) = Ga,b(n) + Ga,b(n-1). Note that the ordinary Fibonacci numbers, as defined in Discussion #7, are defined by F(n) = G0,1(n).

A Function From Binary Strings to Integers: Let Σ = {0, 1}, so that Σ* is the set of all binary strings, including the empty string λ. We define the function f from Σ* to the integers, recursively by the rules (1) f(λ) = 0, (2) for any string w, f(w0) = 1 - f(w), and (3) for any string w, f(w1) = 1 + f(w). (Here "w0" is the string made by appending a 0 to w, and similarly for "w1".)

A Labelled Directed Graph: We will look at several searches of the following labelled directed graph G. Each edge goes in only one direction and is labelled by its cost.


         1           2
   [a] -----> [b] -----> [c]
    ^          |          |
    | 1        | 1        | 3
    |          |          |
    |    5     V    4     V
   [s] -----> [d] -----> [g]
    |          |          ^
    | 6        | 1        | 1
    |          |          |
    V    3     V    1     |
   [e] -----> [f] -----> [j]

A Heuristic: For an A* search of G with goal node g, we will use the following heuristic. For any node x in g, the function h(x) will give the smallest number of edges on any path from x to g. Thus h(a) = h(e) = 3, h(b) = h(s) = h(f) = 2, h(c) = h(d) = h(j) = 1, and h(g) = 0.

Last modified 9 May 2012