adplus-dvertising

Welcome to the Dynamic Programming MCQs Page

Dive deep into the fascinating world of Dynamic Programming with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Dynamic Programming, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Dynamic Programming, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Dynamic Programming. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Dynamic Programming. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Dynamic Programming MCQs | Page 2 of 22

Explore more Topics under Data Structures and Algorithms

Q11.
Consider the following code to find the nth fibonacci term using dynamic programming:
Which technique is used by line 7 of the below code?
1. int fibo(int n)
2. int fibo_terms[100000]  //arr to store the fibonacci numbers
3. fibo_terms[0] = 0
4. fibo_terms[1] = 1
5.  
6. for i: 2 to n
7.  fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
8. 
9. return fibo_terms[n]
Discuss
Answer: (c).Memoization
Q12.
What will be the output when the following code is executed?
#include<stdio.h>
int fibo(int n)
{
      int i;
      int fibo_terms[100];
      fibo_terms[0]=0;
      fibo_terms[1]=1;
      for(i=2;i<=n;i++)
          fibo_terms[i] = fibo_terms[i-2] + fibo_terms[i-1];
      return fibo_terms[n];
}
int main()
{
      int r = fibo(8);
      printf("%d",r);
      return 0;
}
Discuss
Answer: (d).21
Q13.
You are given infinite coins of denominations v1, v2, v3,โ€ฆ..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. This problem can be solved using ____________
Discuss
Answer: (b).Dynamic programming
Q14.
Suppose you have coins of denominations 1, 3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm NOT produce an optimal answer?
Discuss
Answer: (c).6
Q15.
Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer?
Discuss
Answer: (d).100
Q16.
Fill in the blank to complete the code.
#include<stdio.h>
int main()
{
      int coins[10]={1,3,4},lookup[100000];
      int i,j,tmp,num_coins = 3,sum=100;
      lookup[0]=0;
      for(i = 1; i <= sum; i++)
      {
	   int min_coins = i;
	   for(j = 0;j < num_coins; j++)
	   {
	        tmp = i - coins[j];
	        if(tmp < 0)
	         continue;
	        if(lookup[tmp] < min_coins)
	       ______________;
	   }
	   lookup[i] = min_coins + 1;
      }
      printf("%d",lookup[sum]);
      return 0;
}
Discuss
Answer: (b).min_coins = lookup[tmp]
Q17.
You are given infinite coins of N denominations v1, v2, v3,โ€ฆ..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the time complexity of a dynamic programming implementation used to solve the coin change problem?
Discuss
Answer: (d).O(S*N)
Q18.
Suppose you are given infinite coins of N denominations v1, v2, v3,โ€ฆ..,vn and a sum S. The coin change problem is to find the minimum number of coins required to get the sum S. What is the space complexity of a dynamic programming implementation used to solve the coin change problem?
Discuss
Answer: (b).O(S)
Q19.
You are given infinite coins of denominations 1, 3, 4. What is the total number of ways in which a sum of 7 can be achieved using these coins if the order of the coins is not important?

a.

4

b.

3

c.

5

d.

6

Discuss
Answer: (c).5
Q20.
You are given infinite coins of denominations 1, 3, 4. What is the minimum number of coins required to achieve a sum of 7?

a.

1

b.

2

c.

3

d.

4

Discuss
Answer: (b).2

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!