This repository contains a collection of common data structures and algorithms implemented in Java, with a focus on simplicity and elegance.
- Main Technologies: Java (JDK 8+), Bazel (Build System).
- Core Goal: Demonstrate correct and efficient implementations of algorithms.
- Architecture: Organized into thematic packages (e.g.,
datastructures,graphtheory,dp). - Dependencies: Managed via Bazel's
MODULE.bazelusingrules_jvm_external. Key dependencies include JUnit 5, Guava, and Mockito.
Bazel is the primary build system. Each package contains a BUILD file defining libraries and binaries.
-
Run an algorithm:
bazel run //src/main/java/com/williamfiset/algorithms/<subpackage>:<ClassName>
Example:
bazel run //src/main/java/com/williamfiset/algorithms/search:BinarySearch -
Run all tests:
bazel test //src/test/... -
Run tests for a specific package:
bazel test //src/test/java/com/williamfiset/algorithms/<subpackage>:all
-
Run a specific test class:
bazel test //src/test/java/com/williamfiset/algorithms/<subpackage>:<TestClassName>
If Bazel is not available, you can compile and run manually:
mkdir -p classes
javac -sourcepath src/main/java -d classes src/main/java/com/williamfiset/algorithms/<path>/<File>.java
java -cp classes com.williamfiset.algorithms.<package>.<ClassName>- Educational Context: This repository is an educational project. Most comments (except for the most trivial ones) must be preserved during refactoring.
- Purpose: Comments should explain how and why an algorithm or data structure works to aid understanding for students and developers.
- Refactoring: When simplifying code, ensure that the conceptual explanations remain intact.
src/main/java/com/williamfiset/algorithms/: Implementation source code.src/test/java/com/williamfiset/algorithms/: Unit tests (mirrors source structure).utils/: Contains helper classes likeGraphGeneratorand graphUtils.
- Implementation: Add the
.javafile to the appropriate package insrc/main/java/.... - Bazel Configuration:
- Add the file to the
java_library'ssrcsin the package'sBUILDfile (usually handled byglob). - Add a
java_binarytarget for the class if it has amainmethod.
- Add the file to the
- Testing:
- Create a corresponding test file in
src/test/java/.... - Use JUnit 5 (Jupiter) for new tests.
- Add a
java_testtarget in the test directory'sBUILDfile.
- Create a corresponding test file in
- Documentation: Update the
README.mdwith a link to the new implementation and its complexity.
- Solvers: Many algorithms are implemented as "Solver" classes where you instantiate, provide input (e.g., add edges), and then call a
solve()or specific getter method. - Graph Representation: Adjacency lists are commonly represented as
List<List<Edge>>orList<List<Integer>>. - Flow Algorithms: Share a common base
NetworkFlowSolverBase.
README.md: Comprehensive list of all implemented algorithms and data structures.MODULE.bazel: Defines external dependencies and Bazel module configuration.CLAUDE.md: Additional technical guidance for AI assistants.BUILD.bazel/BUILD: Bazel build definitions.