





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Final Examination Solutions
1. a. [5] For n ≥ 1,how many Boolean (i.e. true- or false-valued) functions exist for n Boo- lean variables?
The domain of such a function is { True False, } n, a set of cardinality 2 n^. For a given function, there are two options for the value defined for each variable – thus there are 2 (2 )
n such functions.
2. [10] For n ≥ 1 , how many five-tuples i j k l m, , , , of non-negative values i j k, , ,and l
satisfy i + j + k + l + m ≤n? (Hint: First consider the situation i + j + k + l + m =n and then think about p = n − (i + j + k + l +m) .)
Consider placing n indistinguishable balls into six bins labeled i j k l m, , , , and p. Since the number of balls in the p bin is non-negative, each such placement corre- sponds to a single selection of a five-tuple i j k l m, , , , of non-negative values
i j k l , , , and m satisfying i + j + k + l + m ≤n. There are
n^ +
such placements
of n indistinguishable balls into six bins, therefore the same number of five-tuples i j k l m , , , , of non-negative values i j k l, , , and m satisfying i + j + k + l + m ≤n.
3. a. [10] Using a combinatorial argument, prove that for n ≥ 1 and m ≥ 2 :
0
n k n k
n m m = k
Consider strings of length n selected from the integers {1,2,..., m} with repetition allowed. For each of n positions there are m choices, so there are m n such strings. Alternatively, let k indicate the number of copies of m in the string. The
value of k varies from 0 to n. For a fixed value of k there are
n k
selections for
the placement of the m s and then ( m − 1) choices for the integers {1,2,..., m −1}
in each of the n − k remaining positions. Thus there are ( 1)n^ k
n m k
such strings
with k copies of m , and 0
n n k k
n m k
m n.
b. [10] Using a combinatorial argument, prove that for n ≥ k≥ 0 :
!( )!!
n k n k n k
Consider permutations of length n selected from the integers {1,2,..., n}. There are n! such permutations. Alternatively, let k satisfy n ≥ k≥ 0 and for any per-
mutation first select the positions to be occupied by {1,2,..., k }. There are
n k
such selections. Now permute the values {1,2,..., k }- there are k! such permuta- tions. Finally, permute the n − k values {k + 1, k + 2,..., }n , which can be done in ( n − k)!ways, and place them into the positions of the permutation notoccupied by
the values from {1,2,..., k }. Thus, there are !( )!
n k n k k
such permutations and
this must equal n !.
4. a. [10] For n ≥ 5 , what is the probability that a string of n zeros and ones has exactly 5 ones. (You may assume all strings of n zeros and ones are equally probable.)
5. [15] Prove: If A is a nonempty set, P (A) , the power set of A , is not countably infinite.
Suppose there was a set A such that P (A) were countably infinite. A could not be finite since then |P (A) | = 2 | |A^ and so P (A) would be finite as well. A could not be uncountably infinite since the mapping f :A → P (A) defined by f ( )a = { }a maps A one-to-one into P (A) , so by Theorem 10, P (A) must be uncountably infinite. Lastly, suppose A is countably infinite. Let g : • onto1 1−→Aand h : • 1 1onto−→ P (A) , then g is invertible so h o g −^1 : A onto1 1−→P (A). Define A = { a ∈ A a| ∉ h o g− 1 ( a)}. Since A∈ P (A) , let a = ( h o g −^1 ) −^1 ( A) (that is a sat- isfies h o g −^1 ( a )=A). If a ∈ Athere is a contradiction since then by the definition of A , a ∉ A. Yet if a ∉ Athen for the same reason a ∈ A. Thus either way, there is a contradiction and the assumption that A is countably infinite is false. Since A cannot be finite, uncountably infinite, or countably infinite, A does not exist.
6. a. [10] Prove this corollary to Theorem 6:
1
0
i i j j
−
=
the union (^) i i
∈•
not contained in its predecessors, the union cannot be finite.)
Theorem 6 guarantees that (^) i i
∈•
1
0
i i i j j
a A A
−
=
i
f A ∈
loss of generality that i 1 < i 2 , then
2 1 2
1 1 0
i i i j j
f i a A A
−
=
2 2
1 2 0
i i j j
f i a A
−
=
so f i( ) 1 ≠ f i( 2 )and f is one-to-one. By Theorem 4, (^) i i
∈•
countably infinite.
7. [10] Prove that if f , g ,and h are real-valued functions defined on the natural numbers,
then f = ο ( g )and g = Ο( ) h imply f = ο ( ). h
Since g = Ο( ) h , there exist non-negative constants M and N 1 such that for all n ≥ N 1 , g n( ) ≤ M h n( ). Suppose we are given a positive ε. Since f = ο ( g ) there exists a non-negative constant N 2 such that for all n ≥ N 2 ,
f ( n ) g n( ) M
ε ≤. But then we have for n ≥ max{ N 1 , N 2 },
f ( n ) g n( ) M h n( ) h n( ) M M
ε ε ≤ ≤ = ε. We conclude that f = ο ( ). h
8. [10]. Prove that if 0 < a < b , then n b^ ≠ Ο( na )
Suppose n b^ = Ο ( n a )and thus there exist non-negative constants M and N such
that for all n ≥ N, nb ≤ M na. We note that since a < b ,
1 M b^ −^ aexists and is
positive. Choose
1 n max{ N , M b a− 1}
. We then have n ≥ N and
1 n > M b^ −a, so
n b^ −a^ > M and | nb | = n b^ > Mn a^ = M | na|. This is a contradiction so n b^ ≠ Ο ( na ).
9. [10] Assuming x and y are integer variables, prove correct with respect to precondition
“ y is defined” and postcondition “ x ≠y ”:
if y > 3 then x := y+ if x > 11 then y : = 11 endif else x := y- y := y- endif
______________________ y is defined if y > 3 then ________________ y > 3 x := y+ ________________ ( y > 3) ∧ ( x = y+6) ________________ ( y > 3) ∧( x=9) if x < 11 then __________ ( y > 3) ∧ ( x = 9) ∧ ( x<11) __________ ( y > 3) ∧( x=9) y : = 11 __________ ( y = 11) ∧ ( x=9) __________ x ≠y endif ________________ ( x ≠ y ) ∨ (( y > 3) ∧ ( x = 9) ∧ ( x≥11)) ________________ ( x ≠ y )∨false
11. a. [10] Prove the following code is partially correct with respect to precondition “ n ≥ 1 ”
and postcondition “ ( k / 2 < n) ∧ ( k ≥ n ) ∧ ∃ ≥( j 0 ∋ k = 2 )j ” (assume k and n are integer
variables.):
k := 1 while k < n do k := 2*k endwhile
Be explicit about your loop invariant : I = ( k / 2 < n) ∧ ∃ ≥( j 0 ∋ k=2 )j
____________________ n ≥ 1 k := 1 ____________________ ( n ≥ 1) ∧ ( k =1) ____________________ ( k / 2 < n) ∧ ∃ ≥( j 0 ∋ k=2 )j while k < n do ______________ ( k / 2 < n) ∧ ∃ ≥( j 0 ∋ k = 2 )j ∧ ( k 12. [10] Assuming max, a, b, and c are integer variable and that a, b, and c are defined, de- termine the weakest precondition with respect to the postcondition “(min = a ∨ min = b ∨ min = c ) ∧ (min ≤ a ) ∧ (min ≤ b ) ∧ (min ≤ c )”:
if b < a then { if b < c then min : = b else min := c} else { if c < a then min : = c}