Skip to content

Instantly share code, notes, and snippets.

@arjunrao87
Created February 22, 2015 12:11
Show Gist options
  • Select an option

  • Save arjunrao87/70d4af1178e093fc372c to your computer and use it in GitHub Desktop.

Select an option

Save arjunrao87/70d4af1178e093fc372c to your computer and use it in GitHub Desktop.
Catalan number
public class CatalanNumber {
public static void main( String[] args ){
System.out.println( countTrees( 17) );
}
static long countTrees(int numkeys){
if(numkeys>1){
long sum=0;
for(int i= 1; i <=numkeys; i++){
long lcount = countTrees(i-1);
long rcount = countTrees(numkeys-i);
sum += lcount*rcount;
}
return(sum);
}else
return(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment