Skip to content

Commit b8f3c07

Browse files
authored
Merge branch 'master' into master
2 parents ab942e5 + c498379 commit b8f3c07

15 files changed

Lines changed: 166 additions & 284 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "weekly"
8+
cooldown:
9+
default-days: 7
810

911
- package-ecosystem: "github-actions"
1012
directory: "/.github/workflows/"
1113
schedule:
1214
interval: "daily"
15+
cooldown:
16+
default-days: 7
1317

1418
- package-ecosystem: "maven"
1519
directory: "/"
1620
schedule:
1721
interval: "daily"
22+
cooldown:
23+
default-days: 7
1824
...

.github/workflows/codeql.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030
distribution: 'temurin'
3131

3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@v4
33+
uses: github/codeql-action/init@v4.36.2
3434
with:
3535
languages: 'java-kotlin'
3636

3737
- name: Build
3838
run: mvn --batch-mode --update-snapshots verify
3939

4040
- name: Perform CodeQL Analysis
41-
uses: github/codeql-action/analyze@v4
41+
uses: github/codeql-action/analyze@v4.36.2
4242
with:
4343
category: "/language:java-kotlin"
4444

@@ -55,12 +55,12 @@ jobs:
5555
uses: actions/checkout@v7
5656

5757
- name: Initialize CodeQL
58-
uses: github/codeql-action/init@v4
58+
uses: github/codeql-action/init@v4.36.2
5959
with:
6060
languages: 'actions'
6161

6262
- name: Perform CodeQL Analysis
63-
uses: github/codeql-action/analyze@v4
63+
uses: github/codeql-action/analyze@v4.36.2
6464
with:
6565
category: "/language:actions"
6666
...

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>6.1.0</version>
23+
<version>6.1.1</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -112,7 +112,7 @@
112112
<dependency>
113113
<groupId>com.puppycrawl.tools</groupId>
114114
<artifactId>checkstyle</artifactId>
115-
<version>13.6.0</version>
115+
<version>13.7.0</version>
116116
</dependency>
117117
</dependencies>
118118
</plugin>

src/main/java/com/thealgorithms/ciphers/Caesar.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* @author khalil2535
1010
*/
1111
public class Caesar {
12-
private static char normalizeShift(final int shift) {
13-
return (char) (shift % 26);
12+
private static int normalizeShift(final int shift) {
13+
return ((shift % 26) + 26) % 26;
1414
}
1515

1616
/**
@@ -22,21 +22,18 @@ private static char normalizeShift(final int shift) {
2222
public String encode(String message, int shift) {
2323
StringBuilder encoded = new StringBuilder();
2424

25-
final char shiftChar = normalizeShift(shift);
25+
final int shiftChar = normalizeShift(shift);
2626

2727
final int length = message.length();
2828
for (int i = 0; i < length; i++) {
29-
// int current = message.charAt(i); //using char to shift characters because
30-
// ascii
31-
// is in-order latin alphabet
32-
char current = message.charAt(i); // Java law : char + int = char
29+
final char current = message.charAt(i);
3330

3431
if (isCapitalLatinLetter(current)) {
35-
current += shiftChar;
36-
encoded.append((char) (current > 'Z' ? current - 26 : current)); // 26 = number of latin letters
32+
final int shifted = current + shiftChar;
33+
encoded.append((char) (shifted > 'Z' ? shifted - 26 : shifted)); // 26 = number of latin letters
3734
} else if (isSmallLatinLetter(current)) {
38-
current += shiftChar;
39-
encoded.append((char) (current > 'z' ? current - 26 : current)); // 26 = number of latin letters
35+
final int shifted = current + shiftChar;
36+
encoded.append((char) (shifted > 'z' ? shifted - 26 : shifted)); // 26 = number of latin letters
4037
} else {
4138
encoded.append(current);
4239
}
@@ -53,17 +50,17 @@ public String encode(String message, int shift) {
5350
public String decode(String encryptedMessage, int shift) {
5451
StringBuilder decoded = new StringBuilder();
5552

56-
final char shiftChar = normalizeShift(shift);
53+
final int shiftChar = normalizeShift(shift);
5754

5855
final int length = encryptedMessage.length();
5956
for (int i = 0; i < length; i++) {
60-
char current = encryptedMessage.charAt(i);
57+
final char current = encryptedMessage.charAt(i);
6158
if (isCapitalLatinLetter(current)) {
62-
current -= shiftChar;
63-
decoded.append((char) (current < 'A' ? current + 26 : current)); // 26 = number of latin letters
59+
final int shifted = current - shiftChar;
60+
decoded.append((char) (shifted < 'A' ? shifted + 26 : shifted)); // 26 = number of latin letters
6461
} else if (isSmallLatinLetter(current)) {
65-
current -= shiftChar;
66-
decoded.append((char) (current < 'a' ? current + 26 : current)); // 26 = number of latin letters
62+
final int shifted = current - shiftChar;
63+
decoded.append((char) (shifted < 'a' ? shifted + 26 : shifted)); // 26 = number of latin letters
6764
} else {
6865
decoded.append(current);
6966
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
package com.thealgorithms.dynamicprogramming;
2-
32
import java.util.HashMap;
43
import java.util.Map;
5-
64
/**
7-
* @author Varun Upadhyay (https://github.com/varunu28)
5+
* Collection of Dynamic Programming techniques to solve for the n-th Fibonacci number.
6+
* <p>
7+
* This file showcases Top-Down Memoization ({@code fibMemo}), Bottom-Up Tabulation ({@code fibBotUp}),
8+
* and Space-Optimized Iteration ({@code fibOptimized}).
9+
* <p>
10+
* For alternative structural paradigms, mathematical formulas, or verification steps, see:
11+
* <ul>
12+
* <li>{@link com.thealgorithms.maths.FibonacciLoop} - Standard Iterative (Loop) approach</li>
13+
* <li>{@link com.thealgorithms.recursion.FibonacciSeries} - Naive Recursive approach</li>
14+
* <li>{@link com.thealgorithms.maths.FibonacciJavaStreams} - Functional approach using Java Streams</li>
15+
* <li>{@link com.thealgorithms.maths.FibonacciNumberGoldenRation} - Closed-form expression using Binet's formula</li>
16+
* <li>{@link com.thealgorithms.maths.FibonacciNumberCheck} - Utility to check if a given number is a Fibonacci number</li>
17+
* <li>{@link com.thealgorithms.matrix.matrixexponentiation.Fibonacci} - O(log n) Matrix Exponentiation approach</li>
18+
* </ul>
19+
* * @author Varun Upadhyay (https://github.com/varunu28)
820
*/
921
public final class Fibonacci {
1022
private Fibonacci() {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66
import java.util.stream.Stream;
77

88
/**
9-
* @author: caos321
10-
* @date: 14 October 2021 (Thursday)
9+
* Calculates Fibonacci numbers using a functional programming paradigm with Java Streams.
10+
* <p>
11+
* This specific implementation uses {@link java.util.stream.Stream#iterate} and reductions to generate terms.
12+
* <p>
13+
* For alternative approaches to compute or verify Fibonacci numbers, see:
14+
* <ul>
15+
* <li>{@link com.thealgorithms.maths.FibonacciLoop} - Standard Iterative (Loop) approach</li>
16+
* <li>{@link com.thealgorithms.recursion.FibonacciSeries} - Naive Recursive approach</li>
17+
* <li>{@link com.thealgorithms.dynamicprogramming.Fibonacci} - Dynamic Programming approaches (Memoization, Bottom-Up, Optimized)</li>
18+
* <li>{@link com.thealgorithms.maths.FibonacciNumberGoldenRation} - Closed-form expression using Binet's formula</li>
19+
* <li>{@link com.thealgorithms.maths.FibonacciNumberCheck} - Utility to check if a given number is a Fibonacci number</li>
20+
* <li>{@link com.thealgorithms.matrix.matrixexponentiation.Fibonacci} - O(log n) Matrix Exponentiation approach</li>
21+
* </ul>
22+
* * @author caos321
23+
* @date 14 October 2021 (Thursday)
1124
*/
25+
1226
public final class FibonacciJavaStreams {
1327
private FibonacciJavaStreams() {
1428
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
package com.thealgorithms.maths;
2-
32
import java.math.BigInteger;
4-
53
/**
64
* This class provides methods for calculating Fibonacci numbers using BigInteger for large values of 'n'.
5+
* <p>
6+
* This specific implementation uses an <b>Iterative approach (Loop)</b> with {@code O(n)} time complexity
7+
* and {@code O(1)} space complexity.
8+
* <p>
9+
* For alternative approaches to compute or verify Fibonacci numbers, see:
10+
* <ul>
11+
* <li>{@link com.thealgorithms.recursion.FibonacciSeries} - Naive Recursive approach</li>
12+
* <li>{@link com.thealgorithms.dynamicprogramming.Fibonacci} - Dynamic Programming approaches (Memoization, Bottom-Up, Optimized)</li>
13+
* <li>{@link com.thealgorithms.maths.FibonacciJavaStreams} - Functional approach using Java Streams</li>
14+
* <li>{@link com.thealgorithms.maths.FibonacciNumberGoldenRation} - Closed-form expression using Binet's formula</li>
15+
* <li>{@link com.thealgorithms.maths.FibonacciNumberCheck} - Utility to check if a given number is a Fibonacci number</li>
16+
* <li>{@link com.thealgorithms.matrix.matrixexponentiation.Fibonacci} - O(log n) Matrix Exponentiation approach</li>
17+
* </ul>
718
*/
819
public final class FibonacciLoop {
920

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
* Fibonacci: 0 1 1 2 3 5 8 13 21 ...
55
* This code checks Fibonacci Numbers up to 45th number.
66
* Other checks fail because of 'long'-type overflow.
7+
* <p>
8+
* This class serves as a <b>verification utility</b> rather than a generation algorithm.
9+
* <p>
10+
* For approaches that actively compute the n-th Fibonacci number, see:
11+
* <ul>
12+
* <li>{@link com.thealgorithms.maths.FibonacciLoop} - Standard Iterative (Loop) approach</li>
13+
* <li>{@link com.thealgorithms.recursion.FibonacciSeries} - Naive Recursive approach</li>
14+
* <li>{@link com.thealgorithms.dynamicprogramming.Fibonacci} - Dynamic Programming approaches (Memoization, Bottom-Up, Optimized)</li>
15+
* <li>{@link com.thealgorithms.maths.FibonacciJavaStreams} - Functional approach using Java Streams</li>
16+
* <li>{@link com.thealgorithms.maths.FibonacciNumberGoldenRation} - Closed-form expression using Binet's formula</li>
17+
* <li>{@link com.thealgorithms.matrix.matrixexponentiation.Fibonacci} - O(log n) Matrix Exponentiation approach</li>
18+
* </ul>
719
*/
820
public final class FibonacciNumberCheck {
921
private FibonacciNumberCheck() {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
/**
44
* This class provides methods for calculating Fibonacci numbers using Binet's formula.
55
* Binet's formula is based on the golden ratio and allows computing Fibonacci numbers efficiently.
6+
* <p>
7+
* This specific implementation provides a closed-form solution with an expected {@code O(1)} time complexity.
8+
* <p>
9+
* For alternative approaches to compute or verify Fibonacci numbers, see:
10+
* <ul>
11+
* <li>{@link com.thealgorithms.maths.FibonacciLoop} - Standard Iterative (Loop) approach</li>
12+
* <li>{@link com.thealgorithms.recursion.FibonacciSeries} - Naive Recursive approach</li>
13+
* <li>{@link com.thealgorithms.dynamicprogramming.Fibonacci} - Dynamic Programming approaches (Memoization, Bottom-Up, Optimized)</li>
14+
* <li>{@link com.thealgorithms.maths.FibonacciJavaStreams} - Functional approach using Java Streams</li>
15+
* <li>{@link com.thealgorithms.maths.FibonacciNumberCheck} - Utility to check if a given number is a Fibonacci number</li>
16+
* <li>{@link com.thealgorithms.matrix.matrixexponentiation.Fibonacci} - O(log n) Matrix Exponentiation approach</li>
17+
* </ul>
618
*
719
* @see <a href="https://en.wikipedia.org/wiki/Fibonacci_sequence#Binet's_formula">Binet's formula on Wikipedia</a>
820
*/

0 commit comments

Comments
 (0)