5.QuizDynamicProgrammingonGraphs (Quiz)
5.QuizDynamicProgrammingonGraphs (Quiz)
0. Title: DP on Graph #1
Description: Which of the following graph algorithms is a good example of the DP on
graphs technique?
0.Dijkstra
1.Floyd-Warshall
2.Kosaraju's Algorithm
3.None of these.
1. Title: DP on Graph #2
Description: According to the introductory video on DP + Graphs, any DP solution
has which of the two fundamental inherent properties?
2. Title: DP on Graph #3
Description: Given a 2D grid of size NxM. Each cell of the grid is an integer
representing a score for landing on that cell.
You start at 1,1 and you should reach N,M. In one move you can go from cell(i,j) to
cell(i+1, j) or cell(i, j+1).
Among all possible paths that go from (1,1) to (N,M), find out the maximum possible
score of a path.
Score of a path is the sum of grid[i][j] over all (i,j) visited by the path.
Let us define :
3. Title: DP on Graph #4
Description: For a DAG which of the following provides the correct state
evaluation order?
4. Title: DP on Graph #5
Description: In reference to the video on DAGCNT.
If node A can reach node B and C, then Node A can reach any node that is reachable
from either B or C. Thus we use this relation and node B and node C results to get
all nodes reachable from node A.
For as many as 20,000 nodes what standard template library DS is suggested to speed
up the process?
5. Title: DP on Graph #6
Description: What is the topological sorting of a graph?
6. Title: DP on Graph #7
Description: You are given a DAG, find out the number of unique paths that start
from a given node.
For example for a simple graph with 2 nodes and a directed edge from node 1 to node
2, the number of nodes that start at node 1 is 2(1, 1->2) and that at node number 2
is 1(with path length 0).
What is the optimal time complexity for calculating answers for all the nodes?
0.O(V^2)
1.O(ErootV)
2.O(V^3)
3.O(V + E)
8. Title: DP on Graph #9
Description: Let us modify the previous question. Now you need to find the number
of unique paths of a given length L that start at given node V instead of all
unique paths starting at a given node.
Let the length of a path be the number of edges traversed by the path.
The input graph is a directed graph which may or may not be a DAG.
Define :
<pre>
DP[ V ][ L ] = number of unique paths that start at node V and have length L.
DP[ V ][ 0 ] = 1 for all nodes V.
</pre>
choose the correct recurrence :
<pre>
for length from 1 to L :
for node from 1 to N :
for all neighbours X of node
DP[ node ] [ length ] += DP[ X ][ length - 1]
</pre>
what is the time complexity of the above algorithm?
0.O(N*L)
1.O(N^2*L)
2.O((N*L)^2)
3.O(N*L * log (N*L))