Skip to content

Commit 20e3d53

Browse files
authored
Merge branch 'master' into master
2 parents 1638921 + fb3cec0 commit 20e3d53

File tree

3 files changed

+74
-31
lines changed

3 files changed

+74
-31
lines changed

src/main/java/com/thealgorithms/datastructures/graphs/A_Star.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private static class Graph {
1616
public Graph(int size) {
1717
this.graph = new ArrayList<>();
1818
for (int i = 0; i < size; i++) {
19-
this.graph.set(i, new ArrayList<>());
19+
this.graph.add(new ArrayList<>());
2020
}
2121
}
2222

src/main/java/com/thealgorithms/datastructures/queues/CircularQueue.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,12 @@
44
//Link to the concept: (https://en.wikipedia.org/wiki/Circular_buffer)
55
public class CircularQueue {
66

7-
public static void main(String[] args) {
8-
circularQueue cq = new circularQueue(5);
9-
System.out.println(cq.isEmpty());
10-
System.out.println(cq.isFull());
11-
cq.enQueue(1);
12-
cq.enQueue(2);
13-
cq.enQueue(3);
14-
cq.enQueue(4);
15-
cq.enQueue(5);
16-
17-
System.out.println(cq.deQueue());
18-
System.out.println(cq.deQueue());
19-
System.out.println(cq.deQueue());
20-
System.out.println(cq.deQueue());
21-
System.out.println(cq.deQueue());
22-
System.out.println(cq.isFull());
23-
System.out.println(cq.isEmpty());
24-
cq.enQueue(6);
25-
cq.enQueue(7);
26-
cq.enQueue(8);
27-
System.out.println(cq.peek());
28-
System.out.println(cq.peek());
29-
cq.deleteQueue();
30-
31-
}
32-
}
33-
34-
class circularQueue {
35-
367
int[] arr;
378
int topOfQueue;
389
int beginningOfQueue;
3910
int size;
4011

41-
public circularQueue(int size) {
12+
public CircularQueue(int size) {
4213
arr = new int[size];
4314
topOfQueue = -1;
4415
beginningOfQueue = -1;
@@ -115,4 +86,30 @@ public void deleteQueue() {
11586
System.out.println("The Queue is deleted!");
11687
}
11788

89+
90+
public static void main(String[] args) {
91+
CircularQueue cq = new CircularQueue(5);
92+
System.out.println(cq.isEmpty());
93+
System.out.println(cq.isFull());
94+
cq.enQueue(1);
95+
cq.enQueue(2);
96+
cq.enQueue(3);
97+
cq.enQueue(4);
98+
cq.enQueue(5);
99+
100+
System.out.println(cq.deQueue());
101+
System.out.println(cq.deQueue());
102+
System.out.println(cq.deQueue());
103+
System.out.println(cq.deQueue());
104+
System.out.println(cq.deQueue());
105+
System.out.println(cq.isFull());
106+
System.out.println(cq.isEmpty());
107+
cq.enQueue(6);
108+
cq.enQueue(7);
109+
cq.enQueue(8);
110+
System.out.println(cq.peek());
111+
System.out.println(cq.peek());
112+
cq.deleteQueue();
113+
114+
}
118115
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.thealgorithms.maths;
2+
3+
/*
4+
* Java program for Binomial Cofficients
5+
* Binomial Cofficients: A binomial cofficient C(n,k) gives number ways
6+
* in which k objects can be chosen from n objects.
7+
* Wikipedia: https://en.wikipedia.org/wiki/Binomial_coefficient
8+
*
9+
* Author: Akshay Dubey (https://github.com/itsAkshayDubey)
10+
*
11+
* */
12+
13+
public class BinomialCoefficient {
14+
15+
/**
16+
* This method returns the number of ways in which k objects can be chosen from n objects
17+
*
18+
* @param total_objects Total number of objects
19+
* @param no_of_objects Number of objects to be chosen from total_objects
20+
* @return number of ways in which no_of_objects objects can be chosen from total_objects objects
21+
*/
22+
23+
static int binomialCoefficient(int total_objects, int no_of_objects) {
24+
25+
//Base Case
26+
if(no_of_objects > total_objects) {
27+
return 0;
28+
}
29+
30+
//Base Case
31+
if(no_of_objects == 0 || no_of_objects == total_objects) {
32+
return 1;
33+
}
34+
35+
//Recursive Call
36+
return binomialCoefficient(total_objects - 1, no_of_objects - 1)
37+
+ binomialCoefficient(total_objects - 1, no_of_objects);
38+
}
39+
40+
public static void main(String[] args) {
41+
System.out.println(binomialCoefficient(20,2));
42+
43+
//Output: 190
44+
}
45+
46+
}

0 commit comments

Comments
 (0)