WWW.VUTUBE.EDU.
PK
www.vustuff.com
CS502-Fundamentals of
Algorithms
Final Term Examination – spring 2006
Time Allowed: 150 Minutes
Question No. 1 Marks : 15
Compute all-pairs shortest paths using Floyd-Warshall algorithm on the following
graph
Question No. 2 Marks : 15
Use Prim’s Algorithm starting with vertex “V 1”to find the minimal spanning tree for the
graph
Question No. 3 Marks : 10
Consider the following digraph
(a) Find the adjacency matrix of this graph
(b)List the strongly connected components of this digraph
Question No. 4 Marks : 1
If a graph has v vertices and e edges. Then to obtain a spanning tree we have to
delete
• v edges
• v – e + 5 edges
• v + e edges
• None of these
Question No. 5 Marks : 1
Which of the following is not true about Dijkstra’s algorithm?
I. The length of the shortest path to the start vertex is always
zero
II.It takes time polynomial to the number of vertices
III. It will work on any weighted graph with positive weights
IV. It can be implemented to run in O(V ) time
• Only II
• Only IV
• Both II and IV
• None of these
Question No. 6 Marks : 1
If a problem is not in P, it must be NP-complete
• Yes
• No
• Unknown
Question No. 7 Marks : 15
You are managing 300 million dollars. From this money you can sponsor projects P1, P 2, P 3,
4 P4 with total cost no more than 300 million dollars. The project 1 has cost 60 million and
and
P a profit20 millions ,the, project P2 has cost 240 million and generates a profit500
generates
millions, the project P3 has cost 180 million and generates a profit300 millions ,the project P4
has cost 120 million and generates a profit210 millions
Find out which projects to sponsor so that you get the largest
Hint: This is the classic 0-1 knapsack problem
profit.
Question No. 8 Marks : 1
Consider the following adjacency list:
Which of the following graph(s) describe(s) the above adjacency list?
1.
2.
3.
4.
5.
Question No. 9 Marks : 1
Which statement is true
(I) The running time of Bellman-Ford algorithm is Θ(VE)
(II) Both Dijkstra’s algorithm and Bellman-Ford are based on performing repeated
relaxations
(III) The 0-1 knapsack problem is hard to solve
• Only I
• Only III
• Both I and III
• All of these
Question No. 10 Marks : 1
The recurrence relation of Tower of Hanoi is given below
1 if n =1
Tn() = ⎧
1)1 ifn >1
2(Tn −+
⎨ ⎩
In order to move a tower of 4 rings from one peg to another, how many ring moves are
required
• 15
• 7
• 12
• None of these
Question No. 11 Marks : 1
Which sequence is a valid topological order of the directed graph shown
not below?
• ABDCEF
• ADBCEF
• ABCDFE
• ADBCFE
• ABDFEC
Question No. 12 Marks : 1
Suppose we have two problems A and B .Problem A is polynomial-time reducible and
problem
B is NP-complete. If we reduce problem A into B then problemA becomes NP-complete
• Yes
• No
Question No. 13 Marks : 1
The total degrees of the following graph G
are
• 4
• 5
• 7
• 8
Question No. 14 Marks : 1
Which of the following arrays represent descending (max)
heaps?
I. [10,7,7,2,4,6]
II. [10,7,6,2,4,7]
III. [10,6,7,2,4,6]
IV. [6,6,7,2,4,10]
• Only II
• Only IV
• Both II and IV
• Both I and III
Question No. 15 Marks : 1
Which of the following statement(s) is/are correct?
(a) O(n log n + n 2) = O(n 2).
(b) O(n log n + n 2) = O(n 2 log 2n)
(c) O(c n 2) = O(n 2) where c is a constant.
(d) O(c n 2) = O(c) where c is a constant.
(e) O(c) = O(1) where c is a constant.
• Only (a)
• Only (c)
• Both (a) and (e)
• Both (c) and (e)
• (a) ,(c),(e)
Question No. 16 Marks : 1
The adjacency matrix say A= [aij ] is defined as
1 if { vi ,v j } is anedgeof G
aij = ⎧
0 otherwise
⎨ ⎩
•
0 if { vi ,v j } is anedgeof G
aij = ⎧
1 otherwise
⎨⎩
•
−1 if { vi ,v j } is anedgeof G
aij =
⎧otherwise
0
⎨⎩
•
0 if { vi ,v j } is anedgeof G
aij = ⎧
−1 otherwise
⎨⎩
•
Question No. 17 Marks : 1
Consider the following Huffman Tree
The binary code for the string“TEA” is
• 10 00 010
• 011 00 010
• 10 00 110
• None of these
Question No. 18 Marks : 1
Which of the shortest path algorithms would be most appropriate for finding paths in the
with negative edge weights and
graph
cycles?
I.Dijkstra’s Algorithm
II. Bellman-Ford Algorithm
III. Floyd Warshall Algorithm
• Only II
• Only III
• Both II and III
Question No. 19 Marks : 1
Which of the following orders is nota possible order in whichDepth First Search can visit
the vertices of the directed graph shown
below?
• ABCEFD
• ACEBFD
• ADFEBC
• ADFBCE
• ABFECD