Skip to content

Commit 6884ade

Browse files
authored
Merge branch 'master' into add-library-sort
2 parents f9ce5c0 + ef986c4 commit 6884ade

39 files changed

Lines changed: 735 additions & 174 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

src/main/java/com/thealgorithms/bitmanipulation/BinaryPalindromeCheck.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
* </p>
1010
*
1111
* @author Hardvan
12+
* @see com.thealgorithms.strings.Palindrome
13+
* @see com.thealgorithms.stacks.PalindromeWithStack
14+
* @see com.thealgorithms.maths.LowestBasePalindrome
15+
* @see com.thealgorithms.datastructures.lists.PalindromeSinglyLinkedList
16+
* @see com.thealgorithms.maths.PalindromePrime
17+
* @see com.thealgorithms.maths.PalindromeNumber
1218
*/
1319
public final class BinaryPalindromeCheck {
1420
private BinaryPalindromeCheck() {

src/main/java/com/thealgorithms/conversions/Base64.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,15 @@ public static byte[] decode(String input) {
119119

120120
// Validate padding: '=' can only appear at the end (last 1 or 2 chars)
121121
int firstPadding = input.indexOf('=');
122-
if (firstPadding != -1 && firstPadding < input.length() - 2) {
123-
throw new IllegalArgumentException("Padding '=' can only appear at the end (last 1 or 2 characters)");
122+
if (firstPadding != -1) {
123+
if (firstPadding < input.length() - 2) {
124+
throw new IllegalArgumentException("Padding '=' can only appear at the end (last 1 or 2 characters)");
125+
}
126+
for (int i = firstPadding; i < input.length(); i++) {
127+
if (input.charAt(i) != '=') {
128+
throw new IllegalArgumentException("A padding '=' must not be followed by a non-padding character");
129+
}
130+
}
124131
}
125132

126133
List<Byte> result = new ArrayList<>();

src/main/java/com/thealgorithms/datastructures/graphs/DijkstraAlgorithm.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thealgorithms.datastructures.graphs;
22

33
import java.util.Arrays;
4+
import java.util.PriorityQueue;
45

56
/**
67
* Dijkstra's algorithm for finding the shortest path from a single source vertex to all other vertices in a graph.
@@ -18,6 +19,21 @@ public DijkstraAlgorithm(int vertexCount) {
1819
this.vertexCount = vertexCount;
1920
}
2021

22+
private static class Node implements Comparable<Node> {
23+
int id;
24+
int distance;
25+
26+
Node(int id, int distance) {
27+
this.id = id;
28+
this.distance = distance;
29+
}
30+
31+
@Override
32+
public int compareTo(Node other) {
33+
return Integer.compare(this.distance, other.distance);
34+
}
35+
}
36+
2137
/**
2238
* Executes Dijkstra's algorithm on the provided graph to find the shortest paths from the source vertex to all other vertices.
2339
*
@@ -36,18 +52,25 @@ public int[] run(int[][] graph, int source) {
3652

3753
int[] distances = new int[vertexCount];
3854
boolean[] processed = new boolean[vertexCount];
55+
PriorityQueue<Node> unprocessed = new PriorityQueue<>();
3956

4057
Arrays.fill(distances, Integer.MAX_VALUE);
41-
Arrays.fill(processed, false);
4258
distances[source] = 0;
59+
unprocessed.add(new Node(source, 0));
60+
61+
while (!unprocessed.isEmpty()) {
62+
Node current = unprocessed.poll();
63+
int u = current.id;
4364

44-
for (int count = 0; count < vertexCount - 1; count++) {
45-
int u = getMinDistanceVertex(distances, processed);
65+
if (processed[u]) {
66+
continue;
67+
}
4668
processed[u] = true;
4769

4870
for (int v = 0; v < vertexCount; v++) {
4971
if (!processed[v] && graph[u][v] != 0 && distances[u] != Integer.MAX_VALUE && distances[u] + graph[u][v] < distances[v]) {
5072
distances[v] = distances[u] + graph[u][v];
73+
unprocessed.add(new Node(v, distances[v]));
5174
}
5275
}
5376
}
@@ -56,27 +79,6 @@ public int[] run(int[][] graph, int source) {
5679
return distances;
5780
}
5881

59-
/**
60-
* Finds the vertex with the minimum distance value from the set of vertices that have not yet been processed.
61-
*
62-
* @param distances The array of current shortest distances from the source vertex.
63-
* @param processed The array indicating whether each vertex has been processed.
64-
* @return The index of the vertex with the minimum distance value.
65-
*/
66-
private int getMinDistanceVertex(int[] distances, boolean[] processed) {
67-
int min = Integer.MAX_VALUE;
68-
int minIndex = -1;
69-
70-
for (int v = 0; v < vertexCount; v++) {
71-
if (!processed[v] && distances[v] <= min) {
72-
min = distances[v];
73-
minIndex = v;
74-
}
75-
}
76-
77-
return minIndex;
78-
}
79-
8082
/**
8183
* Prints the shortest distances from the source vertex to all other vertices.
8284
*

src/main/java/com/thealgorithms/datastructures/graphs/DijkstraOptimizedAlgorithm.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)