Solution

advertisement
First Name:
Last Name:
PID:
[Solutions]
COT5405 Design & Analysis of Algorithms
First Midterm Exam – 02/03/2011
Problem
Points
1
10
2
25
3
25
Total
60
Points Received
First Name:
Last Name:
Problem #1 (Solving Recurrence Relations) [10 points] [2 pts each question]
a) T(n)= 4 T(n/4)
Ѳ(n)
b) T(n)=2 T(n/2) + n
Ѳ(n log n )
c) T(n)=2 T(n/2) + n2
Ѳ(n2)
d) T(n)=3 T(n/2) + n3
Ѳ(n3)
e) T(n)=T(n-1) + c2n where c is a constant.
Ѳ(c2n)
PID:
First Name:
Last Name:
PID:
Problem #2 (Strongly Connected Components) [25 points] [5 pts each problem]
Decompose the following graph into strongly connected components. Use the algorithm where
you first run DFS on G and then on GR.
a) Perform DFS on G and write the pre and post numbers of each vertex in table below:
[1 pt off for each mistake, max of 5 off]
Vertex
A
B
C
D
E
F
G
Pre
1
3
2
9
10
4
11
Post
8
6
7
14
13
5
12
b) In what order are the strongly connected components (SCC) found?
[-3 pts for having the order reversed, otherwise all or nothing]
{D,E}, {G}, {A,B,C}. {F}
First Name:
Last Name:
PID:
c) Which are source SCCs and which are sink SCCs?
[3 pts for source; 2 pts for sink ]
Source: {D,E}
Sink: {F}
d) Draw the metagraph.
[1pt. for each edge]
DE
G
ABC
F
e) What is the minimum number of edges you must add to make it strongly connected?
[All or nothing]
1
First Name:
Last Name:
PID:
Problem #3 (Dijkstra’s algorithm) [25 points]
Suppose Dijkstra’s algorithm is run on the following graph, starting at vertex A.
a) Draw a table showing the intermediate distance values of all the vertices after each
iteration of the algorithm. [2 pts per column; all or nothing]
b) Draw the final shortest-path tree. [1pt. for each edge]
First Name:
Last Name:
PID:
c) One of the assumptions with Dijkstra’s algorithm is that the input graph has all positive
edge lengths. If this is not true, then Dijkstra’s algorithm may fail to find shortest paths. Fill
in the edge weights on the graph below so that the algorithm will fail, assuming you start
from vertex A. All edge weights should be integers, and there should be no negative cycles.
[All or nothing]
Download