Professional Documents
Culture Documents
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.
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)
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!