Skip to content

Commit 67312ab

Browse files
Merge branch 'master' into add-padovan-sequence-v2
2 parents 0d2a2bb + e57a675 commit 67312ab

17 files changed

Lines changed: 282 additions & 12 deletions

File tree

.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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.thealgorithms.maths;
2+
// author: Vraj Prajapati @Rosander0
3+
4+
/**
5+
* The Perrin Sequence is a sequence of integers defined by the recurrence relation:
6+
* P(n) = P(n-2) + P(n-3) with initial values P(0) = 3, P(1) = 0, P(2) = 2.
7+
* Example: 3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, 22, 29, 39, 51...
8+
*
9+
* Note: The Perrin Sequence uses the same recurrence relation as the Padovan Sequence
10+
* but has different initial values.
11+
*
12+
* @see <a href="https://en.wikipedia.org/wiki/Perrin_number">
13+
* Wikipedia: Perrin Number</a>
14+
* @see PadovanSequence
15+
*/
16+
public final class PerrinNumber {
17+
18+
private PerrinNumber() {
19+
// Utility class
20+
}
21+
22+
/**
23+
* Calculates the nth term of the Perrin Sequence.
24+
*
25+
* @param n the index of the sequence (must be non-negative)
26+
* @return the nth term of the Perrin Sequence
27+
*/
28+
public static long perrin(final int n) {
29+
if (n < 0) {
30+
throw new IllegalArgumentException("Input must be non-negative!");
31+
}
32+
if (n == 0) {
33+
return 3;
34+
}
35+
if (n == 1) {
36+
return 0;
37+
}
38+
if (n == 2) {
39+
return 2;
40+
}
41+
long a = 3;
42+
long b = 0;
43+
long c = 2;
44+
long result = 0;
45+
for (int i = 3; i <= n; i++) {
46+
result = a + b;
47+
a = b;
48+
b = c;
49+
c = result;
50+
}
51+
return result;
52+
}
53+
}

0 commit comments

Comments
 (0)