Skip to content

Commit fbf0341

Browse files
Merge branch 'TheAlgorithms:master' into master
2 parents bbd7060 + b09766e commit fbf0341

File tree

260 files changed

+10785
-2105
lines changed

Some content is hidden

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

260 files changed

+10785
-2105
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @yanglbme @vil02 @BamaCharanChhandogi @alxkm @siriak
1+
* @DenizAltunkapan @yanglbme @vil02 @BamaCharanChhandogi @alxkm @siriak

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717
if: >-
1818
github.event_name == 'pull_request' &&
1919
github.event.pull_request.head.repo.full_name != github.repository
20-
uses: codecov/codecov-action@v4
20+
uses: codecov/codecov-action@v5
2121
with:
2222
fail_ci_if_error: true
2323
- name: Upload coverage to codecov (with token)
2424
if: >
2525
github.repository == 'TheAlgorithms/Java' &&
2626
(github.event_name != 'pull_request' ||
2727
github.event.pull_request.head.repo.full_name == github.repository)
28-
uses: codecov/codecov-action@v4
28+
uses: codecov/codecov-action@v5
2929
with:
3030
token: ${{ secrets.CODECOV_TOKEN }}
3131
fail_ci_if_error: true

.github/workflows/clang-format-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v4
12-
- uses: DoozyX/clang-format-lint-action@v0.18
12+
- uses: DoozyX/clang-format-lint-action@v0.20
1313
with:
1414
source: './src'
1515
extensions: 'java'

.gitpod.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gitpod/workspace-java-21:2024-09-11-00-04-27
1+
FROM gitpod/workspace-java-21:2025-02-10-10-54-28
22

33
ENV LLVM_SCRIPT="tmp_llvm.sh"
44

DIRECTORY.md

Lines changed: 119 additions & 38 deletions
Large diffs are not rendered by default.

pmd-exclude.properties

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
com.thealgorithms.bitmanipulation.SingleBitOperations=UselessParentheses
21
com.thealgorithms.ciphers.AffineCipher=UselessParentheses
3-
com.thealgorithms.ciphers.ColumnarTranspositionCipher=UnnecessaryFullyQualifiedName
42
com.thealgorithms.ciphers.DES=UselessParentheses
5-
com.thealgorithms.ciphers.HillCipher=UselessParentheses
63
com.thealgorithms.ciphers.RSA=UselessParentheses
74
com.thealgorithms.conversions.AnyBaseToAnyBase=UselessParentheses
85
com.thealgorithms.conversions.AnytoAny=UselessParentheses
9-
com.thealgorithms.conversions.HexToOct=UselessParentheses
10-
com.thealgorithms.conversions.IntegerToRoman=UnnecessaryFullyQualifiedName
11-
com.thealgorithms.datastructures.crdt.LWWElementSet=UselessParentheses
126
com.thealgorithms.datastructures.crdt.Pair=UnusedPrivateField
137
com.thealgorithms.datastructures.graphs.AStar=UselessParentheses
148
com.thealgorithms.datastructures.graphs.AdjacencyMatrixGraph=CollapsibleIfStatements,UnnecessaryFullyQualifiedName,UselessParentheses
159
com.thealgorithms.datastructures.graphs.BipartiteGraphDFS=CollapsibleIfStatements
16-
com.thealgorithms.datastructures.graphs.Kruskal=UselessParentheses
1710
com.thealgorithms.datastructures.hashmap.hashing.HashMapCuckooHashing=UselessParentheses
1811
com.thealgorithms.datastructures.heaps.FibonacciHeap=UselessParentheses
19-
com.thealgorithms.datastructures.heaps.HeapElement=UselessParentheses
2012
com.thealgorithms.datastructures.heaps.HeapNode=UselessParentheses
2113
com.thealgorithms.datastructures.lists.DoublyLinkedList=UselessParentheses
2214
com.thealgorithms.datastructures.lists.SearchSinglyLinkedListRecursion=UselessParentheses
2315
com.thealgorithms.datastructures.lists.SinglyLinkedList=UnusedLocalVariable
2416
com.thealgorithms.datastructures.queues.PriorityQueue=UselessParentheses
25-
com.thealgorithms.datastructures.stacks.NodeStack=UnnecessaryFullyQualifiedName,UnusedFormalParameter
26-
com.thealgorithms.datastructures.stacks.StackArray=UselessParentheses
2717
com.thealgorithms.datastructures.trees.CheckBinaryTreeIsValidBST=UselessParentheses
2818
com.thealgorithms.datastructures.trees.SegmentTree=UselessParentheses
2919
com.thealgorithms.devutils.nodes.LargeTreeNode=UselessParentheses
@@ -32,9 +22,6 @@ com.thealgorithms.devutils.nodes.SimpleTreeNode=UselessParentheses
3222
com.thealgorithms.devutils.nodes.TreeNode=UselessParentheses
3323
com.thealgorithms.divideandconquer.ClosestPair=UnnecessaryFullyQualifiedName,UselessParentheses
3424
com.thealgorithms.divideandconquer.Point=UselessParentheses
35-
com.thealgorithms.dynamicprogramming.MatrixChainMultiplication=UselessParentheses
36-
com.thealgorithms.dynamicprogramming.ShortestSuperSequence=UselessParentheses
37-
com.thealgorithms.dynamicprogramming.UniquePaths=UnnecessarySemicolon
3825
com.thealgorithms.dynamicprogramming.WineProblem=UselessParentheses
3926
com.thealgorithms.maths.BinomialCoefficient=UselessParentheses
4027
com.thealgorithms.maths.Complex=UselessParentheses
@@ -46,45 +33,32 @@ com.thealgorithms.maths.KaprekarNumbers=UselessParentheses
4633
com.thealgorithms.maths.KeithNumber=UselessParentheses
4734
com.thealgorithms.maths.LeonardoNumber=UselessParentheses
4835
com.thealgorithms.maths.LinearDiophantineEquationsSolver=UselessParentheses
49-
com.thealgorithms.maths.MatrixUtil=UselessParentheses
5036
com.thealgorithms.maths.RomanNumeralUtil=UselessParentheses
5137
com.thealgorithms.maths.SecondMinMax=UselessParentheses
5238
com.thealgorithms.maths.SecondMinMaxTest=UnnecessaryFullyQualifiedName
5339
com.thealgorithms.maths.StandardDeviation=UselessParentheses
5440
com.thealgorithms.maths.SumOfArithmeticSeries=UselessParentheses
5541
com.thealgorithms.maths.TrinomialTriangle=UselessParentheses
56-
com.thealgorithms.maths.VampireNumber=CollapsibleIfStatements
5742
com.thealgorithms.maths.Volume=UselessParentheses
58-
com.thealgorithms.matrixexponentiation.Fibonacci=UnnecessaryFullyQualifiedName
5943
com.thealgorithms.misc.Sparsity=UselessParentheses
60-
com.thealgorithms.misc.ThreeSumProblem=UselessParentheses
61-
com.thealgorithms.misc.WordBoggle=UselessParentheses
6244
com.thealgorithms.others.CRC16=UselessParentheses
6345
com.thealgorithms.others.Damm=UnnecessaryFullyQualifiedName
6446
com.thealgorithms.others.Luhn=UnnecessaryFullyQualifiedName
6547
com.thealgorithms.others.Mandelbrot=UselessParentheses
66-
com.thealgorithms.others.MaximumSumOfDistinctSubarraysWithLengthK=CollapsibleIfStatements
6748
com.thealgorithms.others.MiniMaxAlgorithm=UselessParentheses
6849
com.thealgorithms.others.PageRank=UselessParentheses
6950
com.thealgorithms.others.PerlinNoise=UselessParentheses
7051
com.thealgorithms.others.QueueUsingTwoStacks=UselessParentheses
71-
com.thealgorithms.others.QueueWithStack=UselessParentheses
7252
com.thealgorithms.others.Trieac=UselessParentheses
7353
com.thealgorithms.others.Verhoeff=UnnecessaryFullyQualifiedName
7454
com.thealgorithms.searches.InterpolationSearch=UselessParentheses
7555
com.thealgorithms.searches.KMPSearch=UselessParentheses
76-
com.thealgorithms.searches.LinearSearchThread=EmptyCatchBlock
7756
com.thealgorithms.searches.RabinKarpAlgorithm=UselessParentheses
7857
com.thealgorithms.sorts.CircleSort=EmptyControlStatement
79-
com.thealgorithms.sorts.CombSort=UselessParentheses
8058
com.thealgorithms.sorts.DutchNationalFlagSort=UselessParentheses
81-
com.thealgorithms.sorts.LinkListSort=EmptyControlStatement,UnusedLocalVariable
8259
com.thealgorithms.sorts.MergeSortNoExtraSpace=UselessParentheses
83-
com.thealgorithms.sorts.PigeonholeSort=UselessParentheses
8460
com.thealgorithms.sorts.RadixSort=UselessParentheses
8561
com.thealgorithms.sorts.WiggleSort=UselessParentheses
8662
com.thealgorithms.stacks.PostfixToInfix=UselessParentheses
8763
com.thealgorithms.strings.HorspoolSearch=UnnecessaryFullyQualifiedName,UselessParentheses
88-
com.thealgorithms.strings.MyAtoi=UselessParentheses
8964
com.thealgorithms.strings.Palindrome=UselessParentheses
90-
com.thealgorithms.strings.Solution=CollapsibleIfStatements

pom.xml

Lines changed: 13 additions & 23 deletions
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.3</assertj.version>
15+
<assertj.version>3.27.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.11.3</version>
23+
<version>5.12.2</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -31,7 +31,6 @@
3131
<dependency>
3232
<groupId>org.junit.jupiter</groupId>
3333
<artifactId>junit-jupiter</artifactId>
34-
<version>5.11.3</version>
3534
<scope>test</scope>
3635
</dependency>
3736
<dependency>
@@ -43,15 +42,7 @@
4342
<dependency>
4443
<groupId>org.mockito</groupId>
4544
<artifactId>mockito-core</artifactId>
46-
<version>5.14.2</version>
47-
<scope>test</scope>
48-
</dependency>
49-
50-
51-
<dependency>
52-
<groupId>org.junit.jupiter</groupId>
53-
<artifactId>junit-jupiter-api</artifactId>
54-
<version>5.11.3</version>
45+
<version>5.17.0</version>
5546
<scope>test</scope>
5647
</dependency>
5748
<dependency>
@@ -62,23 +53,23 @@
6253
<dependency>
6354
<groupId>org.apache.commons</groupId>
6455
<artifactId>commons-collections4</artifactId>
65-
<version>4.5.0-M2</version>
56+
<version>4.5.0</version>
6657
</dependency>
6758
</dependencies>
6859

6960
<build>
7061
<plugins>
7162
<plugin>
7263
<artifactId>maven-surefire-plugin</artifactId>
73-
<version>3.5.1</version>
64+
<version>3.5.3</version>
7465
<configuration>
7566
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
7667
</configuration>
7768
</plugin>
7869
<plugin>
7970
<groupId>org.apache.maven.plugins</groupId>
8071
<artifactId>maven-compiler-plugin</artifactId>
81-
<version>3.13.0</version>
72+
<version>3.14.0</version>
8273
<configuration>
8374
<source>21</source>
8475
<target>21</target>
@@ -87,15 +78,14 @@
8778
<arg>-Xlint:-auxiliaryclass</arg>
8879
<arg>-Xlint:-rawtypes</arg>
8980
<arg>-Xlint:-unchecked</arg>
90-
<arg>-Xlint:-lossy-conversions</arg>
9181
<arg>-Werror</arg>
9282
</compilerArgs>
9383
</configuration>
9484
</plugin>
9585
<plugin>
9686
<groupId>org.jacoco</groupId>
9787
<artifactId>jacoco-maven-plugin</artifactId>
98-
<version>0.8.12</version>
88+
<version>0.8.13</version>
9989
<executions>
10090
<execution>
10191
<goals>
@@ -114,7 +104,7 @@
114104
<plugin>
115105
<groupId>org.apache.maven.plugins</groupId>
116106
<artifactId>maven-checkstyle-plugin</artifactId>
117-
<version>3.5.0</version>
107+
<version>3.6.0</version>
118108
<configuration>
119109
<configLocation>checkstyle.xml</configLocation>
120110
<consoleOutput>true</consoleOutput>
@@ -125,35 +115,35 @@
125115
<dependency>
126116
<groupId>com.puppycrawl.tools</groupId>
127117
<artifactId>checkstyle</artifactId>
128-
<version>10.18.2</version>
118+
<version>10.23.1</version>
129119
</dependency>
130120
</dependencies>
131121
</plugin>
132122
<plugin>
133123
<groupId>com.github.spotbugs</groupId>
134124
<artifactId>spotbugs-maven-plugin</artifactId>
135-
<version>4.8.6.5</version>
125+
<version>4.9.3.0</version>
136126
<configuration>
137127
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
138128
<includeTests>true</includeTests>
139129
<plugins>
140130
<plugin>
141131
<groupId>com.mebigfatguy.fb-contrib</groupId>
142132
<artifactId>fb-contrib</artifactId>
143-
<version>7.6.5</version>
133+
<version>7.6.9</version>
144134
</plugin>
145135
<plugin>
146136
<groupId>com.h3xstream.findsecbugs</groupId>
147137
<artifactId>findsecbugs-plugin</artifactId>
148-
<version>1.13.0</version>
138+
<version>1.14.0</version>
149139
</plugin>
150140
</plugins>
151141
</configuration>
152142
</plugin>
153143
<plugin>
154144
<groupId>org.apache.maven.plugins</groupId>
155145
<artifactId>maven-pmd-plugin</artifactId>
156-
<version>3.25.0</version>
146+
<version>3.26.0</version>
157147
<configuration>
158148
<printFailingErrors>true</printFailingErrors>
159149
<includeTests>true</includeTests>

spotbugs-exclude.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
<Match>
4242
<Bug pattern="INT_BAD_REM_BY_1" />
4343
</Match>
44-
<Match>
45-
<Bug pattern="ICAST_IDIV_CAST_TO_DOUBLE" />
46-
</Match>
4744
<Match>
4845
<Bug pattern="FE_FLOATING_POINT_EQUALITY" />
4946
</Match>
@@ -86,6 +83,9 @@
8683
<Match>
8784
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
8885
</Match>
86+
<Match>
87+
<Bug pattern="AT_STALE_THREAD_WRITE_OF_PRIMITIVE" />
88+
</Match>
8989
<!-- fb-contrib -->
9090
<Match>
9191
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
@@ -117,9 +117,6 @@
117117
<Match>
118118
<Bug pattern="BL_BURYING_LOGIC" />
119119
</Match>
120-
<Match>
121-
<Bug pattern="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
122-
</Match>
123120
<Match>
124121
<Bug pattern="UTWR_USE_TRY_WITH_RESOURCES" />
125122
</Match>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.thealgorithms.audiofilters;
2+
3+
/**
4+
* Exponential Moving Average (EMA) Filter for smoothing audio signals.
5+
*
6+
* <p>This filter applies an exponential moving average to a sequence of audio
7+
* signal values, making it useful for smoothing out rapid fluctuations.
8+
* The smoothing factor (alpha) controls the degree of smoothing.
9+
*
10+
* <p>Based on the definition from
11+
* <a href="https://en.wikipedia.org/wiki/Moving_average">Wikipedia link</a>.
12+
*/
13+
public class EMAFilter {
14+
private final double alpha;
15+
private double emaValue;
16+
/**
17+
* Constructs an EMA filter with a given smoothing factor.
18+
*
19+
* @param alpha Smoothing factor (0 < alpha <= 1)
20+
* @throws IllegalArgumentException if alpha is not in (0, 1]
21+
*/
22+
public EMAFilter(double alpha) {
23+
if (alpha <= 0 || alpha > 1) {
24+
throw new IllegalArgumentException("Alpha must be between 0 and 1.");
25+
}
26+
this.alpha = alpha;
27+
this.emaValue = 0.0;
28+
}
29+
/**
30+
* Applies the EMA filter to an audio signal array.
31+
*
32+
* @param audioSignal Array of audio samples to process
33+
* @return Array of processed (smoothed) samples
34+
*/
35+
public double[] apply(double[] audioSignal) {
36+
if (audioSignal.length == 0) {
37+
return new double[0];
38+
}
39+
double[] emaSignal = new double[audioSignal.length];
40+
emaValue = audioSignal[0];
41+
emaSignal[0] = emaValue;
42+
for (int i = 1; i < audioSignal.length; i++) {
43+
emaValue = alpha * audioSignal[i] + (1 - alpha) * emaValue;
44+
emaSignal[i] = emaValue;
45+
}
46+
return emaSignal;
47+
}
48+
}

src/main/java/com/thealgorithms/backtracking/ArrayCombination.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static void combine(List<List<Integer>> combinations, List<Integer> curr
4848
for (int i = start; i < n; i++) {
4949
current.add(i);
5050
combine(combinations, current, i + 1, n, k);
51-
current.removeLast(); // Backtrack
51+
current.remove(current.size() - 1); // Backtrack
5252
}
5353
}
5454
}

0 commit comments

Comments
 (0)