GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many balanced parenthesis strings with 6 pairs have nesting depth at most 2?
- A. 42
- B. 64
- C. 32
- D. 132
Correct answer: C. 32
Without the restriction there are C₆ = 132 strings. With depth ≤ 2, a DP over positions and the current depth (0, 1 or 2) gives 32 = 2^(n−1); the unrestricted count is the Catalan number 132.
More Algorithms questions
- In how many ways can a 2 × 10 rectangle be tiled with 2 × 1 dominoes (either orientation) and 2 × 2 squares?
- How many permutations of 7 distinct items have every cycle of length at least 3 (no fixed points and no 2-cycles)?
- Twelve symbols, all with the same frequency 1, are encoded with an optimal Huffman code. What is the total number of bits to encode one…
- In the hiring problem 10 candidates arrive in uniformly random order. The first 3 are only interviewed (never hired); from candidate 4 on…
- Karger's contraction algorithm is run on a connected multigraph with n = 8 vertices, but it stops when 4 super-vertices remain (instead of…
- Which of the following statements is/are correct? I. For metric TSP, doubling an MST and shortcutting gives a 2-approximation. II…