chore(Java): add Catalan Numbers and Priority queue (#577)

pull/592/head
Muhammed Sabah 2021-10-18 00:07:27 +05:30 committed by GitHub
parent dcc53ee9e0
commit d04debeffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,39 @@
// Program to print Catalan Numbers till n using recursive approach.
import java.util.*;
class CatalanNumbers{
public static int findCat(int n){
int val = 0;
if (n<=1) return 1;
for (int i=0;i<n;i++){
val+= findCat(i)*findCat(n-i-1);
}
return val;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i=0;i<=n;i++) System.out.print(findCat(i)+" ");
}
}
/* Applications of Catalan Numbers
-Number of possible full binary trees with n+1 leaves
-Number of possible Binary Search Trees with n nodes
-Number of ways a convex polygon of n+2 sides can be split into triangles by connecting vertices
-Refer this link for more :- https://iq.opengenus.org/applications-of-catalan-numbers/
*/

View File

@ -23,6 +23,7 @@
## Maths
- [Factorial](Maths/factorial_using_big_integer.java)
- [Catalan Numbers](Maths/catalan-numbers.java)
## Queues
- [Circular Queue using Linked List](queues/circular-queue-linked-list.java)
@ -31,7 +32,7 @@
## Scheduling
- [Multi-Level Queue Scheduling](scheduling/multi-level-queue-scheduling.java)
- [Rund Robin](scheduling/round-robin.java)
- [Round Robin](scheduling/round-robin.java)
## Searching
- [Binary Search](searching/binary-search.java)