• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, look at the pattern for n-1 and see how you build n from that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic