chore(Java): add Catalan Numbers and Priority queue (#577)
parent
dcc53ee9e0
commit
d04debeffb
|
@ -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/
|
||||||
|
*/
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
## Maths
|
## Maths
|
||||||
- [Factorial](Maths/factorial_using_big_integer.java)
|
- [Factorial](Maths/factorial_using_big_integer.java)
|
||||||
|
- [Catalan Numbers](Maths/catalan-numbers.java)
|
||||||
|
|
||||||
## Queues
|
## Queues
|
||||||
- [Circular Queue using Linked List](queues/circular-queue-linked-list.java)
|
- [Circular Queue using Linked List](queues/circular-queue-linked-list.java)
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
|
|
||||||
## Scheduling
|
## Scheduling
|
||||||
- [Multi-Level Queue Scheduling](scheduling/multi-level-queue-scheduling.java)
|
- [Multi-Level Queue Scheduling](scheduling/multi-level-queue-scheduling.java)
|
||||||
- [Rund Robin](scheduling/round-robin.java)
|
- [Round Robin](scheduling/round-robin.java)
|
||||||
|
|
||||||
## Searching
|
## Searching
|
||||||
- [Binary Search](searching/binary-search.java)
|
- [Binary Search](searching/binary-search.java)
|
||||||
|
|
Loading…
Reference in New Issue