Skip to content

Commit f42f3ab

Browse files
authored
Merge branch 'master' into cleanup_ColumnarTranspositionCipher
2 parents 00ba48e + 8ea90fd commit f42f3ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+697
-546
lines changed

.gitpod.dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitpod/workspace-java-21:2024-06-17-10-03-09
1+
FROM gitpod/workspace-java-21:2024-07-02-14-18-47
22

33
ENV LLVM_SCRIPT="tmp_llvm.sh"
44

DIRECTORY.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@
490490
* [BitonicSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BitonicSort.java)
491491
* [BogoSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BogoSort.java)
492492
* [BubbleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSort.java)
493-
* [BubbleSortRecursion](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSortRecursion.java)
493+
* [BubbleSortRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BubbleSortRecursive.java)
494494
* [BucketSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/BucketSort.java)
495495
* [CircleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CircleSort.java)
496496
* [CocktailShakerSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/CocktailShakerSort.java)
@@ -515,6 +515,7 @@
515515
* [QuickSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/QuickSort.java)
516516
* [RadixSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/RadixSort.java)
517517
* [SelectionSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSort.java)
518+
* [SelectionSortRecursive](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SelectionSortRecursive.java)
518519
* [ShellSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/ShellSort.java)
519520
* [SimpleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SimpleSort.java)
520521
* [SlowSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/SlowSort.java)
@@ -528,6 +529,7 @@
528529
* [TopologicalSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/TopologicalSort.java)
529530
* [TreeSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/TreeSort.java)
530531
* [WiggleSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/WiggleSort.java)
532+
* [WaveSort](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/sorts/WaveSort.java)
531533
* stacks
532534
* [BalancedBrackets](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/BalancedBrackets.java)
533535
* [DecimalToAnyUsingStack](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/DecimalToAnyUsingStack.java)
@@ -857,6 +859,7 @@
857859
* [BinaryInsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java)
858860
* [BogoSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BogoSortTest.java)
859861
* [BubbleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java)
862+
* [BubbleSortRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortRecursiveTest.java)
860863
* [BucketSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BucketSortTest.java)
861864
* [CircleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CircleSortTest.java)
862865
* [CocktailShakerSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/CocktailShakerSortTest.java)
@@ -874,6 +877,7 @@
874877
* [PancakeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/PancakeSortTest.java)
875878
* [QuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/QuickSortTest.java)
876879
* [SelectionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SelectionSortTest.java)
880+
* [SelectionSortRecursiveTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SelectionSortRecursiveTest.java)
877881
* [ShellSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/ShellSortTest.java)
878882
* [SimpleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SimpleSortTest.java)
879883
* [SlowSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SlowSortTest.java)
@@ -885,6 +889,7 @@
885889
* [TopologicalSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TopologicalSortTest.java)
886890
* [TreeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TreeSortTest.java)
887891
* [WiggleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/WiggleSortTest.java)
892+
* [WaveSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/WaveSortTest.java)
888893
* stacks
889894
* [StackPostfixNotationTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/stacks/StackPostfixNotationTest.java)
890895
* strings

checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<module name="ParenPad"/>
144144
<module name="TypecastParenPad"/>
145145
<module name="WhitespaceAfter"/>
146-
<!-- TODO <module name="WhitespaceAround"/> -->
146+
<module name="WhitespaceAround"/>
147147

148148
<!-- Modifier Checks -->
149149
<!-- See https://checkstyle.org/checks/modifier/index.html -->

pmd-exclude.properties

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ com.thealgorithms.searches.InterpolationSearch=UselessParentheses
7676
com.thealgorithms.searches.KMPSearch=UselessParentheses
7777
com.thealgorithms.searches.LinearSearchThread=EmptyCatchBlock
7878
com.thealgorithms.searches.RabinKarpAlgorithm=UselessParentheses
79-
com.thealgorithms.sorts.BubbleSortRecursion=UselessParentheses
8079
com.thealgorithms.sorts.CircleSort=EmptyControlStatement
8180
com.thealgorithms.sorts.CombSort=UselessParentheses
8281
com.thealgorithms.sorts.DutchNationalFlagSort=UselessParentheses

pom.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1313
<maven.compiler.source>21</maven.compiler.source>
1414
<maven.compiler.target>21</maven.compiler.target>
15-
<assertj.version>3.26.0</assertj.version>
15+
<assertj.version>3.26.3</assertj.version>
1616
</properties>
1717

1818
<dependencyManagement>
1919
<dependencies>
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>5.10.2</version>
23+
<version>5.10.3</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.junit.jupiter</groupId>
3333
<artifactId>junit-jupiter</artifactId>
34-
<version>5.10.2</version>
34+
<version>5.10.3</version>
3535
<scope>test</scope>
3636
</dependency>
3737
<dependency>
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>org.junit.jupiter</groupId>
4646
<artifactId>junit-jupiter-api</artifactId>
47-
<version>5.10.2</version>
47+
<version>5.10.3</version>
4848
<scope>test</scope>
4949
</dependency>
5050
<dependency>
@@ -63,7 +63,7 @@
6363
<plugins>
6464
<plugin>
6565
<artifactId>maven-surefire-plugin</artifactId>
66-
<version>3.3.0</version>
66+
<version>3.3.1</version>
6767
<configuration>
6868
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
6969
</configuration>
@@ -125,7 +125,7 @@
125125
<plugin>
126126
<groupId>com.github.spotbugs</groupId>
127127
<artifactId>spotbugs-maven-plugin</artifactId>
128-
<version>4.8.5.0</version>
128+
<version>4.8.6.2</version>
129129
<configuration>
130130
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
131131
<includeTests>true</includeTests>

spotbugs-exclude.xml

-21
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<Match>
1818
<Bug pattern="DM_NEXTINT_VIA_NEXTDOUBLE" />
1919
</Match>
20-
<Match>
21-
<Bug pattern="NM_CLASS_NAMING_CONVENTION" />
22-
</Match>
2320
<Match>
2421
<Bug pattern="SIC_INNER_SHOULD_BE_STATIC" />
2522
</Match>
@@ -44,9 +41,6 @@
4441
<Match>
4542
<Bug pattern="INT_BAD_REM_BY_1" />
4643
</Match>
47-
<Match>
48-
<Bug pattern="NM_METHOD_NAMING_CONVENTION" />
49-
</Match>
5044
<Match>
5145
<Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE" />
5246
</Match>
@@ -71,9 +65,6 @@
7165
<Match>
7266
<Bug pattern="UWF_UNWRITTEN_FIELD" />
7367
</Match>
74-
<Match>
75-
<Bug pattern="DLS_DEAD_LOCAL_STORE" />
76-
</Match>
7768
<Match>
7869
<Bug pattern="UWF_NULL_FIELD" />
7970
</Match>
@@ -95,9 +86,6 @@
9586
<Match>
9687
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
9788
</Match>
98-
<Match>
99-
<Bug pattern="RV_ABSOLUTE_VALUE_OF_HASHCODE" />
100-
</Match>
10189
<!-- fb-contrib -->
10290
<Match>
10391
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
@@ -120,9 +108,6 @@
120108
<Match>
121109
<Bug pattern="CLI_CONSTANT_LIST_INDEX" />
122110
</Match>
123-
<Match>
124-
<Bug pattern="BED_BOGUS_EXCEPTION_DECLARATION" />
125-
</Match>
126111
<Match>
127112
<Bug pattern="CNC_COLLECTION_NAMING_CONFUSION" />
128113
</Match>
@@ -132,15 +117,9 @@
132117
<Match>
133118
<Bug pattern="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
134119
</Match>
135-
<Match>
136-
<Bug pattern="SPP_USE_ISEMPTY" />
137-
</Match>
138120
<Match>
139121
<Bug pattern="BL_BURYING_LOGIC" />
140122
</Match>
141-
<Match>
142-
<Bug pattern="OI_OPTIONAL_ISSUES_USES_IMMEDIATE_EXECUTION" />
143-
</Match>
144123
<Match>
145124
<Bug pattern="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
146125
</Match>
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
package com.thealgorithms.backtracking;
22

3+
import java.util.ArrayList;
34
import java.util.List;
4-
import java.util.TreeSet;
55

66
/**
7-
* Finds all permutations of 1...n of length k
8-
* @author TheClerici (<a href="https://github.com/TheClerici">git-TheClerici</a>)
7+
* Finds all combinations of 0...n-1 of length k
98
*/
109
public final class ArrayCombination {
1110
private ArrayCombination() {
1211
}
13-
private static int length;
1412

1513
/**
16-
* Find all combinations of 1..n by creating an array and using backtracking in Combination.java
17-
* @param n max value of the array.
18-
* @param k length of combination
19-
* @return a list of all combinations of length k. If k == 0, return null.
14+
* Finds all combinations of length k of 0..n-1 using backtracking.
15+
*
16+
* @param n Number of the elements.
17+
* @param k Length of the combination.
18+
* @return A list of all combinations of length k.
2019
*/
21-
public static List<TreeSet<Integer>> combination(int n, int k) {
22-
if (n <= 0) {
23-
return null;
20+
public static List<List<Integer>> combination(int n, int k) {
21+
if (n < 0 || k < 0 || k > n) {
22+
throw new IllegalArgumentException("Wrong input.");
2423
}
25-
length = k;
26-
Integer[] arr = new Integer[n];
27-
for (int i = 1; i <= n; i++) {
28-
arr[i - 1] = i;
24+
25+
List<List<Integer>> combinations = new ArrayList<>();
26+
combine(combinations, new ArrayList<>(), 0, n, k);
27+
return combinations;
28+
}
29+
30+
private static void combine(List<List<Integer>> combinations, List<Integer> current, int start, int n, int k) {
31+
if (current.size() == k) { // Base case: combination found
32+
combinations.add(new ArrayList<>(current)); // Copy to avoid modification
33+
return;
34+
}
35+
36+
for (int i = start; i < n; i++) {
37+
current.add(i);
38+
combine(combinations, current, i + 1, n, k);
39+
current.removeLast(); // Backtrack
2940
}
30-
return Combination.combination(arr, length);
3141
}
3242
}

src/main/java/com/thealgorithms/datastructures/hashmap/hashing/GenericHashMapUsingArray.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void put(K key, V value) {
4747

4848
// tells which bucket to go to
4949
private int hashFunction(K key) {
50-
int hc = key.hashCode();
51-
return Math.abs(hc) % buckets.length;
50+
return Math.floorMod(key.hashCode(), buckets.length);
5251
}
5352

5453
private void reHash() {

src/main/java/com/thealgorithms/datastructures/heaps/FibonacciHeap.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class FibonacciHeap {
88
private static int totalCuts = 0;
99
private int numOfTrees = 0;
1010
private int numOfHeapNodes = 0;
11-
private int markedHeapNoodesCounter = 0;
11+
private int markedHeapNodesCounter = 0;
1212

1313
/*
1414
* a constructor for an empty Heap
@@ -190,7 +190,7 @@ private void decreaseKey(HeapNode x, int delta) {
190190
* Potential = #trees + 2*#markedNodes
191191
*/
192192
public int potential() {
193-
return numOfTrees + (2 * markedHeapNoodesCounter);
193+
return numOfTrees + (2 * markedHeapNodesCounter);
194194
}
195195

196196
/**
@@ -232,7 +232,7 @@ private void cascadingCuts(HeapNode curr) {
232232
if (!curr.isMarked()) { // stop the recursion
233233
curr.mark();
234234
if (!curr.isRoot()) {
235-
this.markedHeapNoodesCounter++;
235+
this.markedHeapNodesCounter++;
236236
}
237237
} else {
238238
if (curr.isRoot()) {
@@ -252,7 +252,7 @@ private void cascadingCuts(HeapNode curr) {
252252
private void cut(HeapNode curr) {
253253
curr.parent.rank--;
254254
if (curr.marked) {
255-
this.markedHeapNoodesCounter--;
255+
this.markedHeapNodesCounter--;
256256
curr.marked = false;
257257
}
258258
if (curr.parent.child == curr) { // we should change the parent's child

src/main/java/com/thealgorithms/datastructures/heaps/MaxHeap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public MaxHeap(List<HeapElement> listElements) {
2222
System.out.println("Null element. Not added to heap");
2323
}
2424
}
25-
if (maxHeap.size() == 0) {
25+
if (maxHeap.isEmpty()) {
2626
System.out.println("No element has been added, empty heap.");
2727
}
2828
}

src/main/java/com/thealgorithms/datastructures/heaps/MinHeap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public MinHeap(List<HeapElement> listElements) {
2222
System.out.println("Null element. Not added to heap");
2323
}
2424
}
25-
if (minHeap.size() == 0) {
25+
if (minHeap.isEmpty()) {
2626
System.out.println("No element has been added, empty heap.");
2727
}
2828
}

src/main/java/com/thealgorithms/datastructures/heaps/MinPriorityQueue.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
*/
1515
public class MinPriorityQueue {
1616

17-
private int[] heap;
18-
private int capacity;
17+
private final int[] heap;
18+
private final int capacity;
1919
private int size;
2020

21-
// calss the constructor and initializes the capacity
21+
// class the constructor and initializes the capacity
2222
MinPriorityQueue(int c) {
2323
this.capacity = c;
2424
this.size = 0;

src/main/java/com/thealgorithms/devutils/nodes/LargeTreeNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public LargeTreeNode(E data, LargeTreeNode<E> parentNode, Collection<LargeTreeNo
6464
*/
6565
@Override
6666
public boolean isLeafNode() {
67-
return (childNodes == null || childNodes.size() == 0);
67+
return (childNodes == null || childNodes.isEmpty());
6868
}
6969

7070
public Collection<LargeTreeNode<E>> getChildNodes() {

src/main/java/com/thealgorithms/dynamicprogramming/UniquePaths.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
public final class UniquePaths {
2121

22-
private UniquePaths(){};
22+
private UniquePaths() {
23+
}
2324

2425
/**
2526
* Calculates the number of unique paths using a 1D dynamic programming array.

src/main/java/com/thealgorithms/maths/Gaussian.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ private Gaussian() {
77
}
88

99
public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix) {
10-
ArrayList<Double> answerArray = new ArrayList<Double>();
1110
int i;
1211
int j = 0;
1312

@@ -22,8 +21,7 @@ public static ArrayList<Double> gaussian(int matSize, ArrayList<Double> matrix)
2221
}
2322

2423
mat = gaussianElimination(matSize, i, mat);
25-
answerArray = valueOfGaussian(matSize, x, mat);
26-
return answerArray;
24+
return valueOfGaussian(matSize, x, mat);
2725
}
2826

2927
// Perform Gaussian elimination

src/main/java/com/thealgorithms/searches/QuickSelect.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private QuickSelect() {
3131
public static <T extends Comparable<T>> T select(List<T> list, int n) {
3232
Objects.requireNonNull(list, "The list of elements must not be null.");
3333

34-
if (list.size() == 0) {
34+
if (list.isEmpty()) {
3535
String msg = "The list of elements must not be empty.";
3636
throw new IllegalArgumentException(msg);
3737
}

0 commit comments

Comments
 (0)