Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
Matrices A (10 × 20), B (20 × 30) and C (30 × 40) are to be multiplied. What is the minimum number of scalar multiplications?
- A. 8000
- B. 32000
- C. 24000
- D. 18000
Correct answer: D. 18000
(AB)C costs 10·20·30 + 10·30·40 = 6000 + 12000 = 18000; A(BC) costs 20·30·40 + 10·20·40 = 24000 + 8000 = 32000. So the left-to-right order is cheaper.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- What is the length of the longest strictly increasing subsequence of [3, 10, 2, 1, 20, 4, 6, 7]?
- AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?
- What is the minimum number of nodes in an AVL tree of height 4 (a single node has height 0)?
- How many different spanning trees does the complete graph K₄ have?
- How many times in total is fib called (including the first call) when fib(6) is evaluated? c int fib(int n) { if (n <= 1) return n; return…
- What does fun(3) print? c void fun(int n) { if (n > 0) { fun(n - 1); printf("%d ", n); fun(n - 1); } }