Consider The Following Dynamic Programming Implementation Of #2040
Consider the following dynamic programming implementation of the minimum jumps problem:</p> <pre><code class="language-c"> #include<stdio.h> #include<limits.h> int min_jump(int *arr, int len) { int j, idx, jumps[len]; jumps[len - 1] = 0; for(idx = len - 2; idx >= 0; idx--) { int tmp_min = INT_MAX; for(j = 1; j <= arr[idx] && idx + j < len; j++) { if(jumps[idx + j] + 1 < tmp_min) tmp_min = jumps[idx + j] + 1; } jumps[idx] = tmp_min; } return jumps[0]; } int main() { int arr[] ={1, 1, 1, 1, 1, 1, 1, 1, 1},len = 9; int ans = min_jump(arr,len); printf("%d\n",ans); return 0; }</code></pre> <p>Which of the following "for" loops can be used instead of the inner for loop so that the output doesn't change?
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Dynamic Programming - Minimum Number of Jumps - Quiz No.1.
Consider the following dynamic programming implementation of the minimum jumps problem:
#include<stdio.h> #include<limits.h> int min_jump(int *arr, int len) { int j, idx, jumps[len]; jumps[len - 1] = 0; for(idx = len - 2; idx >= 0; idx--) { int tmp_min = INT_MAX; for(j = 1; j <= arr[idx] && idx + j < len; j++) { if(jumps[idx + j] + 1 < tmp_min) tmp_min = jumps[idx + j] + 1; } jumps[idx] = tmp_min; } return jumps[0]; } int main() { int arr[] ={1, 1, 1, 1, 1, 1, 1, 1, 1},len = 9; int ans = min_jump(arr,len); printf("%d\n",ans); return 0; }
Which of the following "for" loops can be used instead of the inner for loop so that the output doesn't change?
for(j = 1; j < arr[idx] + len; j++)
for(j = 0; j < arr[idx] - len; j++)
for(j = idx + 1; j < len && j <= arr[idx] + idx; j++)
No change is required
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes