Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the matrix dimensions array.
DSA C
int arr[] = {10, 20, 30, 40, [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 40 instead of 50 as the last dimension.
✗ Incorrect
The last dimension must be 50 to represent matrices of dimensions 10x20, 20x30, 30x40, and 40x50.
2fill in blank
mediumComplete the code to set the base case for the DP table in matrix chain multiplication.
DSA C
for (int i = 1; i < n; i++) { m[i][i] = [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the base case to 1 or i instead of 0.
✗ Incorrect
The cost of multiplying one matrix is zero because no multiplication is needed.
3fill in blank
hardFix the error in the loop condition to correctly iterate over chain lengths.
DSA C
for (int L = 2; L <= [1]; L++) { // code }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using n or n+1 causes out-of-bound errors.
✗ Incorrect
The chain length L goes up to n-1 because there are n matrices and n-1 gaps between them.
4fill in blank
hardFill both blanks to correctly compute the minimum multiplication cost.
DSA C
for (int k = i; k < j; k++) { int cost = m[i][k] + m[k+1][j] + arr[i-1] [1] arr[k] [2] arr[j]; if (cost < m[i][j]) m[i][j] = cost; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of '*' causes wrong cost calculation.
✗ Incorrect
The cost formula multiplies the dimensions: arr[i-1] * arr[k] * arr[j].
5fill in blank
hardFill all three blanks to complete the nested loops for matrix chain multiplication.
DSA C
for (int L = 2; L <= [1]; L++) { for (int i = 1; i <= n - L + [2]; i++) { int j = i + L - [3]; // compute m[i][j] } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop bounds causing index errors.
✗ Incorrect
L goes up to n-1; i goes up to n-L+1; j is i+L-1 to cover the chain.