Font size
WorksheetsDynamic Programming
Total questions: 82
Worksheet time: 1hrs 2mins
Which of the following is/are property/properties of a dynamic programming problem?
Optimal substructure
Overlapping subproblems
Greedy approach
d) Both optimal substructure and overlapping subproblems
If an optimal solution can be created for a problem by constructing optimal solutions for its subproblems, the problem possesses ____________ property.
Overlapping subproblems
Optimal substructure
Memoization
Greedy
If a problem can be broken into subproblems which are reused several times, the problem possesses ____________ property.
Overlapping subproblems
Optimal substructure
Memoization
Greedy
If a problem can be solved by combining optimal solutions to non-overlapping problems, the strategy is called _____________
Dynamic programming
Greedy
Divide and conquer
Recursion
When dynamic programming is applied to a problem, it takes far less time as compared to other methods that don’t take advantage of overlapping subproblems.
True
False
A greedy algorithm can be used to solve all the dynamic programming problems.
True
False
Which of the following problems is NOT solved using dynamic programming?
0/1 knapsack problem
Matrix chain multiplication problem
Edit distance problem
Fractional knapsack problem
Dynamic programming divides problems into a number of
conflicting objective functions.
decision stages.
unrelated constraints.
policies.
The relationship between stages of a dynamic programming problem is called a(n)
state.
random variable.
node.
Transformation.
In dynamic programming, the output to stage n become the input to
stage n-1.
stage n itself.
stage n+1.
stage n-2.
In dynamic programming, the technique of storing the previously calculated values is called ___________
Saving value property
Storing value property
Memorization
Mapping
Consider the two strings “”(empty string) and “abcd”. What is the edit distance between the two strings?
0
3
4
None of the above
What are 2 things required in order to successfully use the dynamic programming technique?
Optimal sub structure and overlapping sub problems
A problem that can’t be sub divided and is complex
Non overlapping sub problems and intervals
Recursion and a problem that is complex
Dynamic Programming is often used for (choose all that apply):
Optimization problems that involve making a choice that leave one or more subproblems to be solved.
Problems previously solved using divide and conquer that have over lapping subproblems
Non polynomial solution problems
Subproblems where resources are shared
The difference between Divide and Conquer and Dynamic Programming is:
The division of problems and combination of subproblems
Whether the sub problems overlap or not
The way we solve the base case
The depth of recurrence
If a problem can be broken into subproblems which are reused several times, the problem possesses ____________ property.
Overlapping subproblems
Optimal substructure
Memorization
Greedy
Which of the following problems is NOT solved using dynamic programming?
0/1 knapsack problem
Matrix chain multiplication problem
Edit distance problem
Fractional knapsack problem
Find the longest increasing subsequence for the given sequence:
{10, -10, 12, 9, 10, 15, 13, 14}
{10, 12, 15}
{10, 12, 13, 14}
{-10, 12, 13, 14}
{-10, 9, 10, 13, 14}
For any given sequence, there will ALWAYS be a unique increasing subsequence with the longest length.
True
False
You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack?
170
200
160
90
Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?
10*20
20*30
10*30
10*20*30
Consider the strings “PQRSTPQRS” and “PRATPBRQRPS”. What is the length of the longest common subsequence?
6
7
8
9
In which of the following cases will the edit distance between two strings be zero?
When one string is a substring of another
When the lengths of the two strings are equal
When the two strings are equal
The edit distance can never be zero
Suppose each edit (insert, delete, replace) has a cost of one. Then, the maximum edit distance cost between the two strings is equal to the length of the larger string.
True
False
Consider the strings “monday” and “tuesday”. What is the edit distance between the two strings?
3
4
5
6
For which of the following pairs of strings is the edit distance maximum?
Sunday & Monday
Monday & Tuesday
Tuesday & Wednesday
Wednesday & Thursday
Which of the following problems is equivalent to the 0-1 Knapsack problem?
You are given a bag that can carry a maximum weight of W. You are given N items which have a weight of {w1, w2, w3,…., wn} and a value of {v1, v2, v3,…., vn}. You can break the items into smaller pieces. Choose the items in such a way that you get the maximum value
You are studying for an exam and you have to study N questions. The questions take {t1, t2, t3,…., tn} time(in hours) and carry {m1, m2, m3,…., mn} marks. You can study for a maximum of T hours. You can either study a question or leave it. Choose the questions in such a way that your score is maximized
You are given infinite coins of denominations {v1, v2, v3,….., vn} and a sum S. You have to find the minimum number of coins required to get the sum S
None of the mentioned
The 0-1 Knapsack problem can be solved using Greedy algorithm
True
False
Which of the following is the recurrence relation for the matrix chain multiplication problem where mat[i-1] * mat[i] gives the dimension of the ith matrix?
dp[i,j] = 1 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
dp[i,j] = 0 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
dp[i,j] = 1 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j].
dp[i,j] = 0 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j].
What is the time complexity of the dynamic programming implementation of the longest common subsequence problem where length of one string is “m” and the length of the other string is “n”?
O(n)
O(m)
O (m + n)
O(mn)
In Dynamic programming which of the following method does not consist recursion?
memoization
merging
tabulation
none
0/1 knapsack is based on _________ method
greedy method
dynamic programming
divide and conquer
branch and bound
Minimum number of platforms required for trains is
Lists of arrival time and departure time.
Arrival: {900, 940, 950, 1100, 1500, 1800}
Departure: {910, 1200, 1120, 1130, 1900, 2000}
1
2
3
4
In dynamic programming top-down approach is also known as____
tabulation
memoization
optimization
generalization
_______ guarantees to find the optimal solution of a problem if the solution exists
Dynamic programming
Backtracking
Greedy
None
___________ is a method used to store the results of previous function calls to speed up future calculations.
Optimization
Tabulation
Memoization
None
Identify applications of dynamic programming
Fibonacci number series
Knapsack problem
Longest common subsequence
All
Time complexity of longest common sub string using DP is
O(n*m)
O(n+m)
O(n/m)
O(n-m)
Time complexity of longest increasing sub sequences using DP is
O(n^3)
O(n^2)
O(2^n)
O(3^n)
Formula for longest increasing sub sequence is
LS(i) = 1+ max {LS(j)} ; where j<i and A[i] > A[j]
0 ; Otherwise
LS(i) = 1+ min {LS(j)} ; where j<i and A[i] > A[j]
1 ; Otherwise
LS(i) = 1+ max {LS(j)} ; where j<i and A[i] > A[j]
1 ; Otherwise
LS(i) = 1+ max {LS(j)} ; where j>i and A[i] <A[j]
1 ; Otherwise
Which of the following standard algorithms is not Dynamic Programming based
Bellman–Ford Algorithm for single source shortest path
Floyd Warshall Algorithm for all pairs shortest paths
0-1 Knapsack problem
Prim's Minimum Spanning Tree
Which of the following is/are property/properties of a dynamic programming problem?
Optimal substructure
Overlapping subproblems
Distinct Subproblems
Combinatorial
Which technique can be used to get the nth fibonacci term?
Recursion
Dynamic Programming
Both
A greedy algorithm can be used to solve all the dynamic programming problems.
True
False
If a problem can be solved by combining optimal solutions to non-overlapping problems, the strategy is called __________
Dynamic Programming
Divide and Conquer
Recursion
Greedy Technique
The 0/1 Knapsack problem belongs to which domain of problems?
NP Complete
Linear Solution
Sorting
Optimization
What is the space complexity of the following dynamic programming implementation of the Knapsack problem?
O(n)
O(n+W)
O(nW)
O(n2)
Which of the following greedy strategies may give the optimal solution for 0-1 knapsack problem?
Largest profit first
Lightest item first
Heaviest item first
Largest profit per unit weight first
Given a Weighted graph G, Floyd's Algorithm finds
Single source shortest path
All pairs shortest path
Minimum Spanning Tree
Transitive closure
Which of the following recurrence formula is correct for all n>k>0
C(n,k) = C(n-1,k-1) + C(n-1, k) & C(n, 0) = C(n, n )= 1
C(n,k)=C(n-1,k-1)+C(n,k-1) & C(0,n) = C(n,n) = 1
C(n,k)=C(n-1,k-1)+C(n-1,k) & C(0,n) = C(n,n) = 1
C(n,k)=C(n-1,k-1)+C(n-1,k) & C(n,0) = C(n,n) = 0
A sequence of values in a column of DP table for an instance of the knapsack problem is always non-decreasing
True
False
What according to you is a good online quiz app?
Kahoot
Mentimeter
Quizizz
Google Form
Which of the following problems is NOT solved using dynamic programming?
0/1 knapsack problem
Matrix chain multiplication problem
Edit distance problem
Fractional knapsack problem
A greedy algorithm can be used to solve all the dynamic programming problems.
True
False
Dynamic programming differs from the greedy method since the greedy method produces only one feasible solution, which may or may not be optimal, while dynamic programming produces all possible sub-problems at most once, one of which guaranteed to be optimal.
True
False
In dynamic programming, the technique of storing the previously calculated values is called ___________
Saving value property
Storing value property
Memorization
Mapping
What are 2 things required in order to successfully use the dynamic programming technique?
Optimal sub structure and overlapping sub problems
A problem that can’t be sub divided and is complex
Non overlapping sub problems and intervals
Recursion and a problem that is complex
Dynamic Programming is often used for (choose all that apply):
Optimization problems that involve making a choice that leave one or more subproblems to be solved.
Problems previously solved using divide and conquer that have over lapping subproblems
Non polynomial solution problems
Subproblems where resources are shared
The difference between Divide and Conquer and Dynamic Programming is:
The division of problems and combination of subproblems
Whether the sub problems overlap or not
The way we solve the base case
The depth of recurrence
If a problem can be broken into subproblems which are reused several times, the problem possesses ____________ property.
Overlapping subproblems
Optimal substructure
Memorization
Greedy
You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack?
170
200
160
90
Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?
10*20
20*30
10*30
10*20*30
Consider the strings “PQRSTPQRS” and “PRATPBRQRPS”. What is the length of the longest common subsequence?
6
7
8
9
In which of the following cases will the edit distance between two strings be zero?
When one string is a substring of another
When the lengths of the two strings are equal
When the two strings are equal
The edit distance can never be zero
Which of the following problems is equivalent to the 0-1 Knapsack problem?
You are given a bag that can carry a maximum weight of W. You are given N items which have a weight of {w1, w2, w3,…., wn} and a value of {v1, v2, v3,…., vn}. You can break the items into smaller pieces. Choose the items in such a way that you get the maximum value
You are studying for an exam and you have to study N questions. The questions take {t1, t2, t3,…., tn} time(in hours) and carry {m1, m2, m3,…., mn} marks. You can study for a maximum of T hours. You can either study a question or leave it. Choose the questions in such a way that your score is maximized
You are given infinite coins of denominations {v1, v2, v3,….., vn} and a sum S. You have to find the minimum number of coins required to get the sum S
None of the mentioned
The 0-1 Knapsack problem can be solved using Greedy algorithm
True
False
Which of the following is the recurrence relation for the matrix chain multiplication problem where mat[i-1] * mat[i] gives the dimension of the ith matrix?
dp[i,j] = 1 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
dp[i,j] = 0 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]}
dp[i,j] = 1 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j].
dp[i,j] = 0 if i=j
dp[i,j] = min{dp[i,k] + dp[k+1,j]} + mat[i-1]*mat[k]*mat[j].
What is the time complexity of the dynamic programming implementation of the longest common subsequence problem where length of one string is “m” and the length of the other string is “n”?
O(n)
O(m)
O (m + n)
O(mn)
In Greedy method we get ________ Feasible solutions
one
more than one
zero
hundred
Which of the following is true about Huffman Coding.
Huffman coding may become lossy in some cases
Huffman Codes may not be optimal lossless codes in some cases
In Huffman coding, no code is prefix of any other code.
All
The output of Kruskal and Prims algorithm is ________________
Maximum spanning tree
Spanning tree
Minimum spanning tree
None
How do you determine the cost of a spanning tree?
By the sum of costs of the edges of the tree
By the sum of the costs of the edges and vertices of the tree
By the sum of the costs of the vertices of the tree
By the sum of costs of the edges of the graph
The correct encoding of the letter C in this tree is...
11
10
01
00
How do you move through a Huffman tree?
0 = right 1= left
1 = left 2 = right
0 = left 1 = right
0 = middle 1 = back
Knapsack problem is an example of ________ problem
Maximize
Minimize
Neutralized
Balanced
Which is optimal value in the case of job sequence problem Item : 1 2 3 4 5..
Profit : 20 15 10 5 1
Deadline : 2 2 3 3 3
1,3,4
1,2,4
4,2,3
1,5,2
The right child of Binary search tree always should be
less than root node
greater than root node
should be equal to left child
none
When traversing a binary tree, which diagram is post-order?
When traversing a binary tree, which diagram is pre-order?
Given a binary search tree, insert 27, 15, 63, 99, 70 and 85 (in this order) into the binary search tree. What is the post-order traversal?
5,15,27,34,47,54,63,70,72,75,83,85,88,94,99,101
72,54,34,5,27,15,47,63,70,83,75,88,85,101,94,99
15,27,5,47,34,70,63,54,75,85,99,94,101,88,83,72
15,27,5,47,34,63,54,70,75,85,99,94,101,88,83,72
none of the above
