next up previous


CSE 2320 Section 060/061 Spring 1999

Homework 5

Due: May 6, 1999, in class (May 7, 1999, 5:00pm for -10%)

1.
Suppose we want to design a greedy algorithm for the optimal binary search tree problem from HW5 Problem 5. Below are two possible greedy choices we could try. Unfortunately, neither satisfies the greedy choice property. For each, prove by counterexample that the greedy choice does not satisfy the greedy choice property.

(a)
Choose the middle ( $\lfloor n/2 \rfloor$) key as the root.

(b)
Choose the highest frequency key as the root.

2.
Following Figure 23.3 on page 471, execute the breadth-first search procedure on the graph below starting at vertex a. Specifically, show the graph and the contents of the queue Q each time line 9 of the BFS procedure is executed. In addition to the vertex label, show the distance value for each vertex. Shade the predecessor edges added to the breadth-first tree during the course of execution. You do not have to show the colors of the vertices.

\psfig{figure=figures/h52.ps}

3.
Execute TOPOLOGICAL-SORT on the following graph by labeling the vertices with the starting and finishing times produced by depth-first search, and listing the vertices in topological order. Consider vertices in alphabetic order when iterating over a set of vertices.

\psfig{figure=figures/h53.ps}

4.
Execute STRONGLY-CONNECTED-COMPONENTS on the following graph.

\psfig{figure=figures/h54.ps}

(a)
Label the vertices of the above graph with the starting and finishing times produced by the first call to depth-first search, considering vertices in alphabetic order when iterating over a set of vertices.

(b)
Show the transpose of the above graph.

(c)
Label the transpose graph with the starting and finishing times produced by the second call to depth-first search, considering vertices in the proper order.

(d)
Show the strongly-connected components of the original graph.

5.
Following Figure 24.5 on page 508, execute the MST-PRIM procedure on the following graph and show the final minimum spanning tree. Use vertex a as the root vertex and consider vertices in alphabetical order.

\psfig{figure=figures/h55.ps}

6.
Following Figure 27.6 on page 595, show the execution of the Edmonds-Karp algorithm on the following flow network.

\psfig{figure=figures/h56.ps}

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

(a)
aaabbbcccaaabbbcccaaabbbccc

(b)
bcaacabcacbcbacabccabaccabc

8.
Determine a possible pattern 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 9 10
$\pi[i]$ 0 0 1 0 0 0 1 1 0 1

(b)

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


next up previous