Print all combinations of n balanced parentheses
Problem
Implement an algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses.
Example
Input 3 (i.e., 3 pairs of parentheses)
Output ()()(), ()(()), (())(), ((()))
Solution
This is a classic combinatorial problem that manifests itself in many different ways. Such kind of strings are called Dyck strings (see more here), which contain n X’s and n Y’s such that no initial segment of the string has more Y’s than X’s.
[Read More]