Created
February 22, 2015 12:11
-
-
Save arjunrao87/70d4af1178e093fc372c to your computer and use it in GitHub Desktop.
Catalan number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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