You are on page 1of 2

COMP 303-ALGO Pre-Final Practice Session-II Rabranea Bqa

Note: The complexity of below given practice problems have nothing to do with the
complexity of your Final Exam questions. They are merely for your practice before finals.

Session-II Contents : Time Complexity, Graphs & Greedy


approach.

GRAPHS: Estimated Time for Question # 1: 40 min

Question 1. Part A: Below is a directed graph shown: (10 marks)

Suppose Dijkstra’s algorithm is run on a sub graph of the above graph. The sub graph
includes only links between this node-set {A, B, C, E, F, G}. Take node A as the source node
source. Show the final shortest paths from A to each node of this sub-graph. You have to
show each step of the above process with the state of data-structure used at each step
as well.

Part B: Now consider the directed graph shown above (not the given sub graph). Suppose
this graph represents some activities.
How will you order these activities? Show steps done. (7 marks)
Show the ordering and tell in one line (only) which strategy did you use? (1 marks)
Which activity you can do first? (1 mark)
Which activity you can do last? (1 mark)

Part C: In what scenarios Bellman Ford Algorithm can be used to find out the shortest paths
of all nodes from source node instead of Dijstra’s algorithm? (1 marks)
What is the constraint in which both Dijstra’s algorithm and Bellman Ford Algorithm cannot be
used? (1 marks)
What is the space complexity of adjacency list and adjacency matrix if V is the number of
vertices and E is the number of edges in a graph? (2 marks)
Design adjacency list for the graph given in Part A. (6 marks)

Time Complexity: Estimated Time for Question # 2: 20 min


COMP 303-ALGO Pre-Final Practice Session-II Rabranea Bqa

Question 2. Part A: State True/False (7 marks)


(i) f (N) is  (g(N)) if g(N) = O(f (N)), in other words if f grows at least as fast as g.
(ii) N log N + 1000047N =  (N log N).
(iii) All polynomials of order k are O(nk).
(iv) If an algorithm is O(n2), it is also O(n5).
(v) 2.5n ≠ O(n2) ≠ (n2)
(vi) f(n) = Ω(g(n)) && g(n) = Ω(h(n))  f(n) = Ω(h(n))
(vii) n(n+1)/2  (n3)

Part B: What is the time complexity of the following piece of code? (3 marks)

int result=0; // 1
for (int i=0; i<N; i++) // 2
for (int j=i; j<N; j++) { // 3
for (int k=0; k<M; k++) { // 4
int x=0; // 5
while (x<N) { result++; x+=3; } // 6
} // 7
for (int k=0; k<2*M; k++) // 8
if (k%7 == 4) result++; // 9 }

Best of luck!

You might also like