CMPT 307
Solutions to Midterm #2
November 13, 2008
1. True or False? (Below,
Pr
[
X
] stands for the probability of an event
X
.)
[3]
(a) For any random events
A
and
B
,
Pr
[
A
&
B
] =
Pr
[
A
]
·
Pr
[
B

A
].
(b) For any random events
A
1
, A
2
, . . . , A
n
,
Pr
[
A
1
∨
A
2
∨ · · · ∨
A
n
] =
∑
n
i
=1
Pr
[
A
i
].
(c) For independent random events
A
1
, . . . , A
n
,
∑
n
i
=1
Pr
[
A
i
]
≤
1.
Solution:
(a) and (c) are True; (b) is False.
2. Explain
very briefly
why any comparisonbased sorting algorithm will take time at
[5]
least Ω(
n
log
n
) to sort
n
items.
Solution:
There are
n
! possible orderings of
n
elements. A
correct
comparisonbased
algorithm must be able to produce any one of these orderings. Viewing the comparison
based algorithm as a decision tree, this means that the tree has
n
! leaves. But then it
must have at least log(
n
!) = Θ(
n
log
n
) height (= running time of the algorithm).
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
3.
Dynamic Programming
(a) Recall the string matching problem from HW 3:
Given
n, m
∈
N
and binary
[20]
strings
s, t
1
, . . . , t
m
, where
n
is the length of
s
, decide whether
s
can be expressed
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 A.BULATOV
 Graph Theory, String searching algorithm, Random Events, dynamic programming solution

Click to edit the document details