next up previous


CSE 2320 Section 501/571 Fall 1999

Homework 5 Solution

1.
TOPOLOGICAL-SORT

\psfig{figure=figures/hs51.ps}

2.
STRONGLY-CONNECTED-COMPONENTS

\psfig{figure=figures/hs52.ps}

3.
MST-PRIM using vertex a as the root vertex.

\psfig{figure=figures/hs53.ps}

4.
Execution of the Edmonds-Karp algorithm.

\psfig{figure=figures/hs54.ps}

5.
Compute the Knuth-Morris-Pratt prefix function $\pi$ for the following patterns when the alphabet is $\Sigma = \{ {\tt a}, {\tt b}, {\tt
c} \}$.

(a)
abccbabbcaabcbabccbabcba


i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
P[i] a b c c b a b b c a a b c b a b c c b a b c b a
$\pi[i]$ 0 0 0 0 0 1 2 0 0 1 1 2 3 0 1 2 3 4 5 6 7 3 0 1

(b)
aaaaaaaabbbbbbbbaaaaaaaa


i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
P[i] a a a a a a a a b b b b b b b b a a a a a a a a
$\pi[i]$ 0 1 2 3 4 5 6 7 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8

6.
Determine a possible pattern (if any) consistent with the following KMP prefix functions when the alphabet is $\Sigma = \{ {\tt a}, {\tt b}, {\tt
c} \}$.

(a)

i 1 2 3 4 5 6 7 8
$\pi[i]$ 0 1 2 3 0 1 0 1
P[i] a a a a b a b a

The general form of the pattern has characters 1-4, 6 and 8 the same, and characters 5 and 7 different from the others.


(b)

i 1 2 3 4 5 6 7 8
$\pi[i]$ 0 1 2 1 2 1 2 1

No pattern would generate this prefix function, because the first three characters must be the same to generate a prefix of 012. And $\pi[4]=1$means that P[4]=P[1]=a. But then P[1..4] are the same, and therefore, $\pi[4]$ would be 3, not 1.


(c)

i 1 2 3 4 5 6 7 8
$\pi[i]$ 0 0 0 1 1 0 0 0
P[i] a b b a a c c c

The general form of the pattern is that characters 1, 4 and 5 must be the same. Characters 2, 3, 6, 7 and 8 must be different from P[1], and characters 2 and 6 must be different from eachother.


next up previous