wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Dynamic Programming DAA

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

In dynamic programming, the technique of storing the previously calculated values is called ___________

a)

Saving value property

b)

Storing value property

c)

Memorization

d)

Mapping

2.

Consider the two strings “”(empty string) and “abcd”. What is the edit distance between the two strings?

a)

0

b)

3

c)

4

d)

None of the above

3.

What are 2 things required in order to successfully use the dynamic programming technique?

a)

Optimal sub structure and overlapping sub problems

b)

A problem that can’t be sub divided and is complex

c)

Non overlapping sub problems and intervals

d)

Recursion and a problem that is complex

4.

Dynamic Programming is often used for (choose all that apply):

a)

Optimization problems that involve making a choice that leave one or more subproblems to be solved.

b)

Problems previously solved using divide and conquer that have over lapping subproblems

c)

Non polynomial solution problems

d)

Subproblems where resources are shared

5.

The difference between Divide and Conquer and Dynamic Programming is:

a)

The division of problems and combination of subproblems

b)

Whether the sub problems overlap or not

c)

The way we solve the base case

d)

The depth of recurrence

6.

If a problem can be broken into subproblems which are reused several times, the problem possesses ____________ property.

a)

Overlapping subproblems

b)

Optimal substructure

c)

Memorization

d)

Greedy

7.

Which of the following problems is NOT solved using dynamic programming?

a)

0/1 knapsack problem

b)

Matrix chain multiplication problem

c)

Edit distance problem

d)

Fractional knapsack problem

8.

Find the longest increasing subsequence for the given sequence:

{10, -10, 12, 9, 10, 15, 13, 14}

a)

{10, 12, 15}

b)

{10, 12, 13, 14}

c)

{-10, 12, 13, 14}

d)

{-10, 9, 10, 13, 14}

9.

For any given sequence, there will ALWAYS be a unique increasing subsequence with the longest length.

a)

True

b)

False

10.

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?

a)

170

b)

200

c)

160

d)

90

11.

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?

a)

10*20

b)

20*30

c)

10*30

d)

10*20*30

12.

Consider the strings “PQRSTPQRS” and “PRATPBRQRPS”. What is the length of the longest common subsequence?

a)

6

b)

7

c)

8

d)

9

13.

In which of the following cases will the edit distance between two strings be zero?

a)

When one string is a substring of another

b)

When the lengths of the two strings are equal

c)

When the two strings are equal

d)

The edit distance can never be zero

14.

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.

a)

True

b)

False

15.

Consider the strings “monday” and “tuesday”. What is the edit distance between the two strings?

a)

3

b)

4

c)

5

d)

6

16.

For which of the following pairs of strings is the edit distance maximum?

a)

Sunday & Monday

b)

Monday & Tuesday

c)

Tuesday & Wednesday

d)

Wednesday & Thursday

17.

Which of the following problems is equivalent to the 0-1 Knapsack problem?

a)

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

b)

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

c)

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

d)

None of the mentioned

18.

The 0-1 Knapsack problem can be solved using Greedy algorithm

a)

True

b)

False

19.

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?

a)

dp[i,j] = 1 if i=j

dp[i,j] = min{dp[i,k] + dp[k+1,j]}

b)

dp[i,j] = 0 if i=j

dp[i,j] = min{dp[i,k] + dp[k+1,j]}

c)

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].

d)

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].

20.

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”?

a)

O(n)

b)

O(m)

c)

O (m + n)

d)

O(mn)