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 3 of 22

Q21.
You are given infinite coins of denominations 5, 7, 9. Which of the following sum CANNOT be achieved using these coins?
Discuss
Answer: (c).13
Q22.
You are given infinite coins of denominations 3, 5, 7. Which of the following sum CAN be achieved using these coins?
Discuss
Answer: (d).All of the mentioned
Q23.
What is the output of the following program?
#include<stdio.h>
int main()
{
      int coins[10]={1,3,4},lookup[100];
      int i,j,tmp,num_coins = 3,sum=10;
      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)
		 min_coins=lookup[tmp];
	    }
	    lookup[i] = min_coins + 1;
      }
      printf("%d",lookup[sum]);
      return 0;
}

a.

2

b.

3

c.

4

d.

5

Discuss
Answer: (b).3
Q24.
What is the output of the following program?
#include<stdio.h>
int main()
{
      int coins[10]={1,3,4},lookup[100];
      int i,j,tmp,num_coins = 3,sum=14;
      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)
		 min_coins=lookup[tmp];
	   }
	   lookup[i] = min_coins + 1;
      }
      printf("%d",lookup[sum]);
      return 0;
}

a.

2

b.

3

c.

4

d.

5

Discuss
Answer: (c).4
Q25.
Given a one-dimensional array of integers, you have to find a sub-array with maximum sum. This is the maximum sub-array sum problem. Which of these methods can be used to solve the problem?
Discuss
Answer: (d).All of the mentioned
Q26.
Find the maximum sub-array sum for the given elements.
{2, -1, 3, -4, 1, -2, -1, 5, -4}

a.

3

b.

5

c.

8

d.

6

Discuss
Answer: (b).5
Q27.
Find the maximum sub-array sum for the given elements.
{-2, -1, -3, -4, -1, -2, -1, -5, -4}
Discuss
Answer: (d).-1
Q28.
Consider the following naive method to find the maximum sub-array sum:
Which line should be inserted to complete the below code?
#include<stdio.h>
int main()
{
     int arr[1000]={2, -1, 3, -4, 1, -2, -1, 5, -4}, len=9;
     int cur_max, tmp_max, strt_idx, sub_arr_idx;
     cur_max = arr[0];
     for(strt_idx = 0; strt_idx < len; strt_idx++)
     {
	  tmp_max=0;
	  for(sub_arr_idx = strt_idx; sub_arr_idx < len; sub_arr_idx++)
	  {
	       tmp_max +=arr[sub_arr_idx];
	       if(tmp_max > cur_max)
		 _____________;
	  }
     }
     printf("%d",cur_max);
     return 0;
}

Discuss
Answer: (d).cur_max = tmp_max
Q29.
What is the time complexity of the naive method used to find the maximum sub-array sum in an array containing n elements?
Discuss
Answer: (a).O(n^2)
Q30.
What is the space complexity of the naive method used to find the maximum sub-array sum in an array containing n elements?
Discuss
Answer: (b).O(1)
Page 3 of 22

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!