Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java 21
- name: Set up Java 25
uses: actions/setup-java@v4
with:
java-version: '21'
java-version: '25'
distribution: 'temurin'
cache: maven

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A collection of **algorithm implementations** covering fundamental computer scie
## 🚀 Quick Start

### Prerequisites
- **Java 21+** (project compiles with Java 21)
- **Java 25+** (project compiles with Java 21)
- **Maven 3.6+** (tested with 3.9+, uses plugins requiring 3.6+)
- **JUnit 5.10+** (managed automatically by Maven)
- Git (optional)
Expand Down
81 changes: 21 additions & 60 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<version>1.0.0</version>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
</properties>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>src</testSourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
Expand All @@ -24,6 +25,17 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.15.0</version>
<configuration>
<!-- Exclude duplicates under main/ and test/ so only src/topics/ is compiled -->
<excludes>
<exclude>main/**</exclude>
<exclude>test/**</exclude>
</excludes>
<testExcludes>
<testExclude>main/**</testExclude>
<testExclude>test/**</testExclude>
</testExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -38,6 +50,8 @@
<show>package</show>
<additionalJOption>-Xdoclint:-html,-missing</additionalJOption>
<encoding>UTF-8</encoding>
<!-- src/ is the correct sourcepath root: topics.sorting.bubble -> src/topics/sorting/bubble/ -->
<sourcepath>${basedir}/src</sourcepath>
</configuration>
</plugin>
</plugins>
Expand All @@ -47,18 +61,18 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<version>5.12.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.2</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.2</version>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -73,57 +87,4 @@
</dependency>
</dependencies>

<profiles>
<profile>
<!-- Activates automatically in CI where src/main/java does not exist -->
<id>ci</id>
<activation>
<file>
<missing>src/main/java</missing>
</file>
</activation>
<build>
<resources>
<resource>
<directory>src/topics</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<!-- <sourceDirectory> is not allowed in profile builds (BuildBase);
use build-helper to add src/topics as an additional source root in CI -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/topics</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<!-- src/ is the correct root: package topics.sorting.bubble -> src/topics/sorting/bubble/ -->
<sourcepath>${basedir}/src</sourcepath>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
4 changes: 2 additions & 2 deletions src/topics/branchandbound/agents/AgentsTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import topics.branchandbound.BranchAndBound;
import topics.branchandbound.Node;
import topics.branchandbound.utils.BranchAndBound;
import topics.branchandbound.utils.Node;

/**
* <h1>Task Assignment</h1>
Expand Down
4 changes: 2 additions & 2 deletions src/topics/branchandbound/eightpuzzle/EightPuzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.ArrayList;
import java.util.UUID;

import topics.branchandbound.BranchAndBound;
import topics.branchandbound.Node;
import topics.branchandbound.utils.BranchAndBound;
import topics.branchandbound.utils.Node;

/**
* <h1>The 8-Puzzle</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/topics/branchandbound/rectangles/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.UUID;

import topics.branchandbound.Node;
import topics.branchandbound.utils.Node;

/**
* <h1>Board State for Rectangle Placement</h1>
Expand Down
4 changes: 2 additions & 2 deletions src/topics/branchandbound/rectangles/RectanglesPlacement.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import java.util.List;
import java.util.UUID;

import topics.branchandbound.BranchAndBound;
import topics.branchandbound.Node;
import topics.branchandbound.utils.BranchAndBound;
import topics.branchandbound.utils.Node;

/**
* <h1>Optimal Placement of Rectangles</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import topics.branchandbound.BranchAndBound;
import topics.branchandbound.utils.BranchAndBound;

/**
* <h1>Sequential Performance Benchmark (Rectangle Placement)</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import topics.branchandbound.BranchAndBoundThreads;
import topics.branchandbound.utils.threads.BranchAndBoundThreads;

/**
* <h1>Concurrent Performance Benchmark (Rectangle Placement)</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

import topics.branchandbound.BranchAndBoundThreads;
import topics.branchandbound.utils.threads.BranchAndBoundThreads;

/**
* <h1>Optimal Placement of Rectangles (Concurrent Execution)</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/topics/branchandbound/utils/BranchAndBound.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.branchandbound;
package topics.branchandbound.utils;

import java.util.List;
import org.slf4j.Logger;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/branchandbound/utils/Heap.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.branchandbound;
package topics.branchandbound.utils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/branchandbound/utils/Node.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.branchandbound;
package topics.branchandbound.utils;

import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package topics.branchandbound;
package topics.branchandbound.utils.threads;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import topics.branchandbound.utils.Node;

/**
* <h1>Concurrent Branch and Bound Execution Engine</h1>
* <p>
Expand Down
4 changes: 3 additions & 1 deletion src/topics/branchandbound/utils/threads/HeapThreads.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.branchandbound;
package topics.branchandbound.utils.threads;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -9,6 +9,8 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.PriorityBlockingQueue;

import topics.branchandbound.utils.Node;

/**
* <h1>Concurrent State Space Queue (Heap)</h1>
* <p>
Expand Down
4 changes: 3 additions & 1 deletion src/topics/branchandbound/utils/threads/WorkerThread.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package topics.branchandbound;
package topics.branchandbound.utils.threads;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import topics.branchandbound.utils.Node;

/**
* <h1>Concurrent Worker Thread</h1>
* <p>
Expand Down
1 change: 1 addition & 0 deletions src/topics/divideconquer/maxsum/MaxSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private int maxSumByDivision(int left, int right, int[] v) {
}

// Prevent Integer Overflow mathematically
// (left + right) / 2 can overflow if left and right are large, so we use:
int center = left + (right - left) / 2;

int maxLeft = maxSumByDivision(left, center, v);
Expand Down
62 changes: 62 additions & 0 deletions src/topics/divideconquer/maxsum/MaxSumBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package topics.divideconquer.maxsum;

import java.util.concurrent.ThreadLocalRandom;

/**
* <h1>Empirical Runtime Analysis for Maximum Subarray Sum</h1>
* <p>
* This benchmarking utility demonstrates the dramatic performance differences
* between algorithmic complexities: Cubic O(N&sup3;), Quadratic O(N&sup2;),
* and Linearithmic O(N log N).
* </p>
*
* <h2>Educational Note</h2>
* <p>
* The execution loop is strictly capped at N = 4096.
* If allowed to scale indefinitely, the O(N&sup3;) algorithm would cause
* the CPU to hang for hours due to combinatorial explosion.
* </p>
*
* @author vicegd
*/
public class MaxSumBenchmark {
public static void main(String[] args) {
MaxSum engine = new MaxSum();

System.out.println("=======================================================================");
System.out.println(" BENCHMARKING MAXIMUM SUBARRAY SUM: O(N³) vs O(N²) vs O(N log N) ");
System.out.println("=======================================================================");
System.out.printf("%-12s | %-15s | %-15s | %-15s%n", "Array Size", "Cubic O(N³)", "Quadratic O(N²)", "D&C O(N log N)");
System.out.println("-----------------------------------------------------------------------");

// Capped at 4096 to prevent the Cubic algorithm from freezing the execution environment.
for (int n = 10; n <= 4096; n *= 2) {
int[] v = new int[n];

// Populate with both positive and negative values (crucial for this specific problem)
for (int i = 0; i < n; i++) {
v[i] = ThreadLocalRandom.current().nextInt(-1000, 1000);
}

// 1. Measure Cubic Time O(N³)
long t1 = System.currentTimeMillis();
engine.maxSubarrayCubic(v);
long t2 = System.currentTimeMillis();

// 2. Measure Quadratic Time O(N²)
long t3 = System.currentTimeMillis();
engine.maxSubarrayQuadratic(v);
long t4 = System.currentTimeMillis();

// 3. Measure Divide & Conquer Time O(N log N)
long t5 = System.currentTimeMillis();
engine.maxSubarrayDivideAndConquer(v);
long t6 = System.currentTimeMillis();

// Output formatted results
System.out.printf("N = %-8d | %-12d ms | %-12d ms | %-12d ms%n",
n, (t2 - t1), (t4 - t3), (t6 - t5));
}
System.out.println("=======================================================================");
}
}
17 changes: 11 additions & 6 deletions src/topics/divideconquer/median/Median.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package topics.divideconquer.median;

import topics.sorting.quicksort.Quicksort;

/**
* <h1>Median Calculation</h1>
* <p>
Expand Down Expand Up @@ -42,10 +40,9 @@ public int medianBySorting(int[] v) {

// Prevent side-effects: Do not mutate the original array
int[] copy = v.clone();

Quicksort quicksort = new Quicksort();
quicksort.sort(copy);


sort(copy, 0, copy.length - 1);

int centerPosition = copy.length / 2;
return copy[centerPosition];
}
Expand Down Expand Up @@ -82,6 +79,14 @@ public int medianQuickselect(int[] v) {
* Private Quickselect recursive helper.
* Finds the k-th smallest element within the segment boundaries.
*/
/** Recursive quicksort using the local Util partition scheme. */
private void sort(int[] v, int left, int right) {
if (left >= right) return;
int pivot = Util.partition(v, left, right);
sort(v, left, pivot - 1);
sort(v, pivot + 1, right);
}

private int quickselect(int left, int right, int[] v, int k) {
// Base case: If the segment is only one element long, we've found it
if (left == right) {
Expand Down
2 changes: 1 addition & 1 deletion src/topics/introduction/helloworld/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.introduction;
package topics.introduction.helloworld;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/introduction/helloworld/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package topics.introduction;
package topics.introduction.helloworld;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down
Loading
Loading