Question
In the dynamic programming solution for Matrix Chain
Multiplication, the outermost loop iterates over the len (chain length). What are the correct loop bounds for len and i? // n is the number of matrices (arr.size() for dimensions array) // dp is a 2D array for (int len = __________) { // Line to complete len loop   for (int i = __________); i < n - len; i++) { // Line to complete i loop     int j = i + len;     // ... inner k loop and calculations   } }Solution
• Code Analysis: o n is the number of matrices. o len should iterate from the smallest possible chain length (2 matrices) up to the total number of matrices (n). o i should iterate through all possible starting points for a subproblem of length len. o j = i + len calculates the ending index of the subproblem. • Explanation of Correct Answer (B): len = 2; len < n; len++ and i = 0 o len loop:  len starts from 2 because a chain of length 1 (a single matrix) requires no multiplication. The smallest meaningful chain is two matrices.  len < n: The chain length len goes up to n-1 (if n is the number of matrices, then n-1 is the maximum chain length for subproblems, as j goes up to n-1). If n is the size of the arr (dimensions array), then n-1 is the number of matrices. The loop should go up to n-1 matrices, so len < n is correct. o i loop:  i starts from 0 because the first matrix can be at index 0.  i < n - len: This ensures that j = i + len does not exceed the bounds of the matrix array. If n is the number of matrices, then i can go up to n - len. For example, if len = n-1, i can only be 0.
X and Y run a 3 km race along a circular course of length 300 m. Their speeds are in the ratio 3:2. If they start together in the same direction, how m...
In an objective type test of 90 questions, 5 marks are allotted for every correct answer and 2 marks are deducted for every wrong answer. After attempt...
Consider the following addition problem :
3P + 4P + PP + PP = RQ2; where P, Q and R are different digits.
What is the arithmetic mean...
Consider the following multiplication problem:
(PQ) × 3 = RQQ, where P, Q and R are different digits and R # 0.
What is the value of...
A Statement followed by Conclusion - I and conclusion – II is given below. You have to take the Statement to be true even if it seems to be at varian...
Consider two Statements and a Question :
Statement - 1: Each of A and D is heavier than each of B, E and F, but none of them is the heaviest. ...
If 32019 is divided by 10, then what is the remainder?
Two candidates X and Y contested an election. 80% of voters cast their vote and there were no invalid votes. There was no NOTA (None of the above) opti...
A pie chart gives the expenditure on five different items A, B, C, D and E in a household. If B, C, D and E correspond to 90°, 50°, 45° and 75° res...
A person X wants to distribute some pens among six children A, B, C, D, E and F. Suppose A gets twice the number of pens received by B, three times tha...