# [R], <s>112</s> <s>107</s> 103 bytes Non-recursive approach. We generate all 2^2n 2n-character strings of "(" and ")" using `expand.grid` (via their ASCII codes 40 and 41) and then grep to see which combinations give balanced parentheses. Via http://rachbelaid.com/recursive-regular-experession/ <!-- language-all: lang-r --> function(n)sort(grep("^(\\((?1)*\\))(?1)*$",apply(expand.grid(rep(list(41:40),2*n)),1,intToUtf8),,T,T)) [Try it online!][TIO-jotuoag1] Explanation - "^(\\((?1)*\\))(?1)*$" = regex for balanced parens ^ # match a start of the string ( # start of expression 1 \\( # open parens (?1)* # optional repeat of any number of expression 1 (recursive) # allows match for parentheses like (()()())(()) where ?1 is (\\((?1)*\\)) \\) # close parens ) # end of expression 1 (?1)* # optional repeat of any number of expression 1 $ # end of string function(n) sort( grep("^(\\((?1)*\\))(?1)*$", # search for regular expression matching parens apply( expand.grid(rep(list(41:40),2*n)) # generate 2^(2n) 40, 41 combinations ,1,intToUtf8) # turn into all 2^(2n) combinations of "(",")" ,,T,T) # return the values that match the regex ) # sort them [R]: https://www.r-project.org/ [TIO-jotuoag1]: https://tio.run/##HcpNCsIwEAbQuxQX85VRjHQhIniJ1FUQSpuUQJmEdATr5ePP7i1eqeG6r@Epo8YkJFhTUZqLz9Q8yDmim0HrHPDHruEh52Uj/8qDTIe5xIl@eYmrUmcu3RF8agVgw1HUpl7DGcyWLVDvftRU4ttTAH0z6gc "R – Try It Online" # [R], 107 bytes Usual recursive approach. -1 thanks @Giuseppe <!-- language-all: lang-r --> f=function(n,x=0:1)`if`(n,sort(unique(unlist(Map(f,n-1,lapply(seq(x),append,x=x,v=0:1))))),intToUtf8(x+40)) [Try it online!][TIO-jor09nco] [R]: https://www.r-project.org/ [TIO-jor09nco]: https://tio.run/##HYxBCsIwEEWvM4MjpNCFFHoEd@q6pWZgIEzSZCrRy8fo23ze4r/cGs986GYSFZTq7KYBF@GlS4nZ4FDZD98nSDG4rgmY9DxQWFMKbyh@h4rUxeuz3yu9/okfJGq3eDe@QD2NDrE9/GYxy8cDI7hpxPYF "R – Try It Online"