ICS.6D: Fall 2007, Quiz 5 Solutions
1)
[32 points]
State whether each of the following is as a recursive definition of some function
from nonnegative integers
to integers or not.
Circle the right answer:
a)
f(0) = 1,
f(n) = f(n – 1)
for n ≥ 1
Good one, f(n)=1 for all n≥0
b)
f(0) = 1,
f(n) = f(n – 2)
for n ≥ 1
Failed, because f(1) is “defined” using f(-1)
c)
f(0) = 1,
f(n) = f(n – 2)
for n ≥ 2
Failed, because f(1) is undefined.
d)
f(0) = 1, f(1) = 1, f(n) = f(n – 2)
for n ≥ 3
Failed, because f(2) is undefined
2)
[36 points]
State whether each of the following is a good recursive definition of the set of (all)
even positive integers
, i.e. {2,4,6,8,10,…}, or not.
Circle the right answer:
a)
2
∈
S, and if n
∈
S then n+2
∈
S.
Good One
b)
2
∈
S, and if n
∈
S then 2*n
∈
S.
Failed, because e.g. 6 is not in this set S.
(Btw, this is a good recursive definition but of a different set, namely S = {2
k
| k ≥ 1}.)
c)
2
∈
S, and if n
1
∈
S and n
2
∈
S then (n
1
+n
2
)
∈
S.
Good One.
Note that we can have n
1
=n
2
.
3)
[32 points]
Here are definitions of (1) a string, (2) a string inverse, and (3) a string bit-wise xor:
1)
λ
is a string, and
s•b
is a string for any string
s
and bit
b
.
2)
inv(λ) = λ
, and
inv(s•b) = b•inv(s)
for any string
s
and bit
b
.
3)
xor(λ) = 0
, and
xor(s•b) = (b+xor(s) mod 2)
Fact 4)
xor(b•s) = (b+xor(s) mod 2)
for any string
s
and bit
b
,
Using these definitions show by structural induction that
xor
(
inv(s)
)
= xor(s)
for any string
s
:
a) [6 points]
Base case
.
First, write the string which you need to consider: ___
Empty string, i.e.
λ
Now prove that the claim is true for this string:
xor(inv(
λ
)) = xor(
λ
) because inv(
λ
) =
λ
by the base case of definition (2).
b) [26 points]
Inductive case
.
First, write a string which you need to consider: ___
s•b
_______
Now prove that the claim is true for this string assuming it holds for its component(s):
xor(inv(
s•b
)) = xor
(
b•
inv(
s
)
)
% by recursive case of definition (2)
This
preview
has intentionally blurred sections.
Sign up to view the full version.

This is the end of the preview.
Sign up
to
access the rest of the document.
- Fall '07
- Jarecki
- Recursion, Recurrence relation, 2k, 5-digit
-
Click to edit the document details