• Post Reply Bookmark Topic Watch Topic
  • New Topic

Print all possible patterns of "(" and ")" for a input number  RSS feed

 
siddharth paul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I want to print all possible combinations of "(" and ")" for any given number.
Let me explain it with an example.

value of n possible patterns
n=1 ()
n=2 (()), ()()
n=3 ((())), (())() ()(()), ()()()
n=4 (((()))), ((()))() ()((())), (())(()),()()()()

there is no place for ")(" .

I need some basic approach to follow.

What in my mind is something like print(n), print(n-l)print(l) print(l)print(n-l), print(l)*n

and then i have to call it in recursive way.

I am not very sure about my way
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, look at the pattern for n-1 and see how you build n from that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!