CSc 340 Test 3
Wednesday
18 April 2001

SUGGESTED ANSWERS

1.
Show the nine comparisons which would occur when the tournament
algorithm is applied to find the 2nd largest entry in the array
x[1],.
..,x[8] = {8, 4, 9, 7, 3, 2, 6, 1}.
In practice, of course, the
algorithm does not know the entries and only compares them.
8  8 
4 /
\
9  9  9  9
Now we search for the
8  8  8
7 /
/
maximum among the losers
7 /
/
3  3 
/
to 9
6 /
2 /
\
/
6  6  6 
1 /
Every pair of parallel lines stand for 1 comparison.
There are 9
such comparisons.
2.
Assume G=(V,E,W) is a weighted, directed graph such that the subgraph
of all nodes reachable from node 1 is a tree rooted at node 1.
Also assume
that int A[][] is the adjacency matrix for G, where A[i][j]=0 indicates the
lack of an arc from i to j, and A[i][j]>0 is the weight when there is an
arc from i to j.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '01
 varies

Click to edit the document details