Consider the following recursive implementation:
#include<stdio.h>
#include<limits.h>
int min_jumps(int *arr, int strt, int end)
{
int idx;
if(strt == end)
return 0;
if(arr[strt] == 0) // jump cannot be made
return INT_MAX;
int min = INT_MAX;
for(idx = 1; idx <= arr[strt] && strt + idx <= end; idx++)
{
int jumps = min_jumps(____,____,____) + 1;
if(jumps < min)
min = jumps;
}
return min;
}
int main()
{
int arr[] ={1, 3, 5, 8, 9, 2, 6, 7, 6},len = 9;
int ans = min_jumps(arr, 0, len-1);
printf("%d\n",ans);
return 0;
}
Which of these arguments should be passed by the min_jumps function represented by the blanks?
#include<stdio.h>
#include<limits.h>
int min_jumps(int *arr, int strt, int end)
{
int idx;
if(strt == end)
return 0;
if(arr[strt] == 0) // jump cannot be made
return INT_MAX;
int min = INT_MAX;
for(idx = 1; idx <= arr[strt] && strt + idx <= end; idx++)
{
int jumps = min_jumps(____,____,____) + 1;
if(jumps < min)
min = jumps;
}
return min;
}
int main()
{
int arr[] ={1, 3, 5, 8, 9, 2, 6, 7, 6},len = 9;
int ans = min_jumps(arr, 0, len-1);
printf("%d\n",ans);
return 0;
}A. arr, strt + idx, end
B. arr + idx, strt, end
C. arr, strt, end
D. arr, strt, end + idx
Answer: Option A
What is the main principle behind Dynamic Programming (DP)?
A. Recursion with memoization.
B. Greedy approach.
C. Divide and conquer.
D. Overlapping subproblems and optimal substructure.
Which of the following problems can be solved using Dynamic Programming?
A. Binary Search
B. Depth-First Search
C. Longest Common Subsequence
D. Quick Sort
What is the key advantage of using Dynamic Programming over plain recursion?
A. It makes the code simpler.
B. It reduces the time complexity by storing results of subproblems.
C. It uses more memory.
D. It makes the code simpler.
In the context of Dynamic Programming, what does the term "memoization" refer to?
A. Using a stack to manage function calls.
B. A method for dividing problems.
C. Storing intermediate results to avoid redundant calculations.
D. A technique to speed up sorting.

Join The Discussion