The minimum number of scalar multiplication required, for parenthesization of a matrix-chain product whose sequence of dimensions for four matrices is <5, 10, 3, 12, 5> is
405
Matrix-chain multiplication is solved by dynamic programming: \(m[i,j] = \min_{i \le k \lt j}\{m[i,k] + m[k+1,j] + p_{i-1}p_k p_j\}\), with m[i, i] = 0. The dimensions give A1 = 5×10, A2 = 10×3, A3 = 3×12, A4 = 12×5, i.e. p0…p4 = 5, 10, 3, 12, 5.
Step 1 — Chains of length 2: m[1,2] = 5·10·3 = 150, m[2,3] = 10·3·12 = 360, m[3,4] = 3·12·5 = 180.
Step 2 — m[1,3] = min(m[1,2] + 5·3·12, m[2,3] + 5·10·12) = min(150 + 180, 360 + 600) = 330.
Step 3 — m[2,4] = min(m[2,3] + 10·12·5, m[3,4] + 10·3·5) = min(360 + 600, 180 + 150) = 330.
Step 4 — m[1,4]: split after A1 gives 0 + 330 + 5·10·5 = 580; split after A2 gives 150 + 180 + 5·3·5 = 405; split after A3 gives 330 + 0 + 5·12·5 = 630. The minimum is 405, achieved by (A1A2)(A3A4).
| m[i, j] | j = 1 | j = 2 | j = 3 | j = 4 |
|---|---|---|---|---|
| i = 1 | 0 | 150 | 330 | 405 |
| i = 2 | — | 0 | 360 | 330 |
| i = 3 | — | — | 0 | 180 |
| i = 4 | — | — | — | 0 |
630 and 580 are the costs of the other two top-level splits, which are not optimal, and 480 is not produced by any parenthesization of this chain.
405 option is correct.
Consider the problem of a chain <A1, A2, A3> of three matrices. Suppose that the dimensions of the matrices are 10 × 100, 100 × 5 and 5 × 50 respectively. There are two different ways of parenthesization : (i) ((A1 A2)A3) and (ii) (A1(A2 A3)). Computing the product according to the first parenthesization is ________ times faster in comparison to the second parenthesization.
Let \(n = 4\) and \((a_{1}, a_{2}, a_{3}, a_{4}) = (\text{do, if, int, while})\). Let \(p(1:4) = \left(\frac{3}{8}, \frac{3}{8}, \frac{1}{8}, \frac{1}{8}\right)\) and \(q(1:4) = \left(\frac{2}{8}, \frac{3}{8}, \frac{1}{8}, \frac{1}{8}, \frac{1}{8}\right)\) where p(i) and q(i) denotes the probability with which we search \(a_{i}\) and the identifier x being searched satisfy \(a_{i} \lt x \lt a_{i+1}\) respectively. The optimal search tree is given by :
Given two sequences X and Y :
\(X = \langle a, b, c, b, d, a, b \rangle\)
\(Y = \langle b, d, c, a, b, a \rangle\).
The longest common subsequence of X and Y is :
The travelling salesman problem can be solved in :
A triangulation of a polygon is a set of T chords that divide the polygon into disjoint triangles. Every triangulation of n-vertex convex polygon has _____ chords and divides the polygon into _____ triangles.
Arrange the following steps in the correct order to solve the Knapsack problem using Dynamic Programming.
(A) Define the base case when the capacity is zero (0) or no items are left to consider
(B) Compute the maximum value that can be obtained using items up to the i-th item and a knapsack capacity of 0
(C) Identify subproblems and their dependencies based on items weights and values
(D) Initialize a table to store results of subproblems
(E) Iterate through each item and each possible Capacity to fill the table
Choose the correct answer from the options given below :
Consider the problem of a chain <A1, A2, A3> of three matrices. Suppose that the dimensions of the matrices are 10 × 100, 100 × 5 and 5 × 50 respectively. There are two different ways of parenthesization : (i) ((A1 A2)A3) and (ii) (A1(A2 A3)). Computing the product according to the first parenthesization is ________ times faster in comparison to the second parenthesization.
Let \(n = 4\) and \((a_{1}, a_{2}, a_{3}, a_{4}) = (\text{do, if, int, while})\). Let \(p(1:4) = \left(\frac{3}{8}, \frac{3}{8}, \frac{1}{8}, \frac{1}{8}\right)\) and \(q(1:4) = \left(\frac{2}{8}, \frac{3}{8}, \frac{1}{8}, \frac{1}{8}, \frac{1}{8}\right)\) where p(i) and q(i) denotes the probability with which we search \(a_{i}\) and the identifier x being searched satisfy \(a_{i} \lt x \lt a_{i+1}\) respectively. The optimal search tree is given by :
Given two sequences X and Y :
\(X = \langle a, b, c, b, d, a, b \rangle\)
\(Y = \langle b, d, c, a, b, a \rangle\).
The longest common subsequence of X and Y is :
The travelling salesman problem can be solved in :