The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

Algorithms

Miscellaneous

Problem :-
Given the number of parenthesis pairs, print all possible combination of Balanced Parenthesis.
Suppose no. of parenthesis pairs = 3
Possible combination of Balanced Parenthesis are :-
{ } { } { }  |  { } { { } }  |  { { } } { }  |  { { } { } }  |  { { { } } }

Solution :-
The implementation shown below uses a recursive approach to print the combinations of balanced parenthesis keeping track of the number of open parenthesis and closed parenthesis at any point of recursion.
At any point, we have two possible options :
1 ) Print a open parenthesis ( if available ) and recursively check for a possible solution.
2 ) Print a closed parenthesis ( if a corresponding open parenthesis has been printed ) and recursively check for a possible solution.
We consider both the options at each point of recursion to print all possible combinations of balanced parenthesis. See the implementation below.