Data Structures & AlgorithmsModerateGATE CS · TCS NQT

In how many different ways can the product of 5 matrices A·B·C·D·E be fully parenthesised (grouping by brackets, keeping the order of factors)?

  1. A. 42
  2. B. 5
  3. C. 14
  4. D. 16

Correct answer: C. 14

The number of full binary bracketings of n factors is the Catalan number C(n−1). For 5 factors that is C₄ = 14. Using C₅ = 42 counts one extra factor, and powers of 2 count only the shapes of the tree.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic