Skip to content

Commit c7dbdce

Browse files
Merge branch 'master' into add-friendly-number
2 parents 3ac12ba + 631eae3 commit c7dbdce

21 files changed

Lines changed: 452 additions & 12 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v6
11+
- uses: actions/checkout@v7
1212
- name: Set up JDK
1313
uses: actions/setup-java@v5
1414
with:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v6
14+
- uses: actions/checkout@v7
1515
- uses: DoozyX/clang-format-lint-action@v0.20
1616
with:
1717
source: './src'

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout repository
24-
uses: actions/checkout@v6
24+
uses: actions/checkout@v7
2525

2626
- name: Set up JDK
2727
uses: actions/setup-java@v5
@@ -52,7 +52,7 @@ jobs:
5252

5353
steps:
5454
- name: Checkout repository
55-
uses: actions/checkout@v6
55+
uses: actions/checkout@v7
5656

5757
- name: Initialize CodeQL
5858
uses: github/codeql-action/init@v4

.github/workflows/infer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run_infer:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v6
18+
- uses: actions/checkout@v7
1919

2020
- name: Set up JDK
2121
uses: actions/setup-java@v5

.github/workflows/project_structure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
check_structure:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v6
18+
- uses: actions/checkout@v7
1919
- uses: actions/setup-python@v6
2020
with:
2121
python-version: '3.13'

.github/workflows/update-directorymd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate Directory Markdown
1+
name: Generate Directory Markdown
22

33
on:
44
push:
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout Repository
17-
uses: actions/checkout@v6
17+
uses: actions/checkout@v7
1818
with:
1919
persist-credentials: false
2020

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<dependency>
113113
<groupId>com.puppycrawl.tools</groupId>
114114
<artifactId>checkstyle</artifactId>
115-
<version>13.5.0</version>
115+
<version>13.6.0</version>
116116
</dependency>
117117
</dependencies>
118118
</plugin>

src/main/java/com/thealgorithms/tree/HeavyLightDecomposition.java renamed to src/main/java/com/thealgorithms/datastructures/trees/HeavyLightDecomposition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.tree;
1+
package com.thealgorithms.datastructures.trees;
22

33
import java.util.ArrayList;
44
import java.util.List;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.thealgorithms.maths;
2+
// author: Vraj Prajapati @Rosander0
3+
4+
/**
5+
* The Jacobsthal Sequence is a sequence of integers defined by the recurrence relation:
6+
* J(n) = J(n-1) + 2*J(n-2) with initial values J(0) = 0, J(1) = 1.
7+
* Example: 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341...
8+
*
9+
* @see <a href="https://en.wikipedia.org/wiki/Jacobsthal_number">
10+
* Wikipedia: Jacobsthal Number</a>
11+
*/
12+
public final class JacobsthalNumber {
13+
14+
private JacobsthalNumber() {
15+
// Utility class
16+
}
17+
18+
/**
19+
* Calculates the nth term of the Jacobsthal Sequence.
20+
*
21+
* @param n the index of the sequence (must be non-negative)
22+
* @return the nth term of the Jacobsthal Sequence
23+
*/
24+
public static long jacobsthal(final int n) {
25+
if (n < 0) {
26+
throw new IllegalArgumentException("Input must be non-negative!");
27+
}
28+
if (n == 0) {
29+
return 0;
30+
}
31+
if (n == 1) {
32+
return 1;
33+
}
34+
long a = 0;
35+
long b = 1;
36+
long result = 0;
37+
for (int i = 2; i <= n; i++) {
38+
result = b + 2 * a;
39+
a = b;
40+
b = result;
41+
}
42+
return result;
43+
}
44+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.thealgorithms.maths;
2+
3+
/**
4+
* The Padovan Sequence is a sequence of integers defined by the recurrence relation:
5+
* P(n) = P(n-2) + P(n-3) with initial values P(0) = P(1) = P(2) = 1.
6+
* Example: 1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37...
7+
*
8+
* @see <a href="https://en.wikipedia.org/wiki/Padovan_sequence">
9+
* Wikipedia: Padovan Sequence</a>
10+
* @author Vraj Prajapati (@Rosander0)
11+
*/
12+
public final class PadovanSequence {
13+
14+
private PadovanSequence() {
15+
// Utility class
16+
}
17+
18+
/**
19+
* Calculates the nth term of the Padovan Sequence.
20+
*
21+
* @param n the index of the sequence (must be non-negative)
22+
* @return the nth term of the Padovan Sequence
23+
*/
24+
public static long padovan(final int n) {
25+
if (n < 0) {
26+
throw new IllegalArgumentException("Input must be non-negative. Received: " + n);
27+
}
28+
if (n <= 2) {
29+
return 1;
30+
}
31+
long a = 1;
32+
long b = 1;
33+
long c = 1;
34+
long result = 0;
35+
for (int i = 3; i <= n; i++) {
36+
result = a + b;
37+
a = b;
38+
b = c;
39+
c = result;
40+
}
41+
return result;
42+
}
43+
}

0 commit comments

Comments
 (0)