Beruflich Dokumente
Kultur Dokumente
c
nil
d
nil
f
nil
e
nil
8
6
2
11
7
4
1
8
a
b c
d
f
e
8
Final Exam Fall 2010 Semester BSCS Student ID:_________________
3
a) Now you will run the instruction 8 to 17 and fill the following table of
figures and once you have finished running the algorithm and filling the
table, you will fill the output graph with final values, showing the
minimal spanning tree. (25)
u = a
Q = {b,c,d,e,f}
v = b, e
u = b
Q = {e,c,d,f}
v = a, e, c
u = e
Q = {c,d,f}, {d,c,f}, {f,d,c}
v = b, d, f
u = f
Q = {d, c}
v = e, d
u = d
Q = {c}
v = e, f, c
u = c
Q = {}
v = b, d
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
d
2
d
f
6
f
e
1
e
a
8
8
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
d
2
d
f
6
f
e
1
e
a
8
8
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
b
8
d
f
6
f
e
1
e
a
8
8
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
b
8
d
e
7
f
e
1
e
a
8
8
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
b
8
d
f
e
a
8
8
6
2
11
7
4
1
8
a
Nil
0
b
a
4
c
d
f
e
a
8
8
Final Exam Fall 2010 Semester BSCS Student ID:_________________
4
b) Discuss and give the detailed analysis of the algorithm MST-PRIM given
above. (5)
O(V+E)
Final Exam Fall 2010 Semester BSCS Student ID:_________________
5
Question 2 (10)
Apply Master Theorem to following recurrences, if possible and justify your answer.
a) I(n) = 2I [
n
2
+n
3
Solution
o = 2, b = 2, (n) = n
3
n
Iog
b
u
= n
Iog
2
2
= n
= (n) > n
Iog
b
u
it mcons cosc S o Hostcr
i
sIbcorcm is opplicoblc,
Complcxity o I(n) = 0((n)) = 0(n
3
)
b) I(n) = 16I [
n
4
+n
2
Solution
o = 16, b = 4, (n) = n
2
n
Iog
b
u
= n
Iog
4
16
= n
2
= (n) = n
Iog
b
u
it mcons cosc 2 o Hostcr
i
sIbcorcm is opplicoblc,
Complcxity o I(n) = 0(n
Iog
b
u
lg n) = 0(n
2
lg n)
Final Exam Fall 2010 Semester BSCS Student ID:_________________
6
Question 3 ()
a) Suppose we have a graph G = (V, E). There is non-overlapping partition of set
of vertices V, i.e. S and V-S. Identify all crosses and the light edge in the
following diagram. (4)
S V S
Crosses: (b,c) , (h,i), (h,g)
Light Edge: (h,g)
b) Build both the Adjacency List Representation and Adjacency Matrix
Representation of the following graph. (18)
Final Exam Fall 2010 Semester BSCS Student ID:_________________
7
c) Adjacency Matrix Representation of a Graph is Time efficient. (1)
d) Adjacency List Representation of a Graph is Space efficient. (1)
e) Space Complexity of Adjacency Matrix Representation is O(VV). (1)
f) Space Complexity of Adjacency List Representation is O(V+E). (1)
g) Given a graph G(V, E) and distinguished source vertex s, Breadth First Search
algorithm explores the edges of G to discover every vertex that is reachable
from the source s. (1)
h) Breadth First search algorithm produces a Breadth First Tree. (1)
i) Depth First search algorithm produces a Depth First Forest. (1)
j) Give two elements of Dynamic Programming. (2)
Optimal Structure
Overlapping sub-problem space
k) Give two elements of Greedy Algorithms. (2)
Optimal Structure
Greedy Choice
l) What is difference between Quick Sort Algorithm and Randomized Quick Sort?
(2)
In Quick Sort, first element is selected as a pivot, on the other hand, in
Randomized Quick Sort, a random number from the input array is selected as a
pivot.