CS 336
Sample Questions for Test 2
November 29, 2000
1. Construct pre- and post-condition assertions for the following program, using the Hoare rules.
{ P > 0 }
CONTINUE := true
( while CONTINUE do
Q := 2
LEAVE := false
( while not LEAVE do
K := 1;
( while K * Q <= P do
if K*Q = P then LEAVE = true else skip;
K := K + 1;
)
Q := Q + 1;
if LEAVE then skip else CONTINUE := FALSE;
)
}
Q := Q - 1;
2. Let T be the complete partial order consisting of a, b, c where c is the lower bound of both a and b and neither a nor b is a lower bound of the other.
Construct T x T x T.
3. Let S = { a, b, c }. Let f and g be functions f:SxS->S and g:S -> S. Let E be the set of all legal function calls.
Define a Godel numbering system for E and show how to compute the Godel number of
g(f(a,b))
4. (a) Write an algorithm in pseudo code for checking whether a number N is in the set of prime numbers.
(b) Write an algorithm in pseudo code for deciding whether a number N is in the set of prime numbers.
5. Let P be a checker for set S and let Q be a checker for set Z\S (where Z is the set of natural numbers and S is a subset of Z). Write an algorithm for deciding whether N is a member of S.