Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

• triangulations
• gambler’s ruin
• binary trees
• trees

…from the Flajolet/Sedgewick coursera analysis of algorithms

in R:

catalan <- function(n) {
if(n

(This is slow above catalan(10) though, so here’s a memoised version. Then if you want to run above catalan(250) you’ll need to adjust options(expressions=5e3) to something higher; otherwise the nesting of calls goes too deep.)