algorithms README

The project's README from github.com/williamfiset/algorithms. As one markdown file: README.md.

License: MIT Bazel Tests README Checker Sponsor

Algorithms & data structures project

Algorithms and data structures are fundamental to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. This repository's goal is to demonstrate how to correctly implement common data structures and algorithms in the simplest and most elegant ways.

🎬 Many of the algorithms and data structures in this repo have companion video explanations on the William Fiset YouTube channel — so if the code alone doesn't click, grab some popcorn and watch the videos!

Running an algorithm implementation

To compile and run any of the algorithms here, you need at least JDK version 8 and Bazel

This project uses Bazel as its build system. Install Bazel by following the official installation guide.

Run a single algorithm like this:

bazel run //src/main/java/com/williamfiset/algorithms/<subpackage>:<ClassName>

For instance:

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/sorting:all

Compiling and running with only a JDK

If you don't want to use Bazel, you can compile and run with just the JDK:

Create a classes folder

cd Algorithms
mkdir classes

Compile the algorithm

javac -sourcepath src/main/java -d classes src/main/java/<relative-path-to-java-source-file>

Run the algorithm

java -cp classes <class-fully-qualified-name>

Example

$ javac -d classes -sourcepath src/main/java src/main/java/com/williamfiset/algorithms/search/BinarySearch.java
$ java -cp classes com.williamfiset.algorithms.search.BinarySearch

Data Structures

Dynamic Programming

Dynamic Programming Classics

Dynamic Programming Problem Examples

Adhoc

Tiling problems

Geometry

More geometry algorithms

Graph theory

Tree algorithms

Network flow

Main graph theory algorithms

algorithms (williamfiset/algorithms)

competitive-programming
Searching Database…

What is this?A large open-source collection of classic algorithms and data structures implemented in Java, written to demonstrate correct implementations in the simplest and most elegant ways.
Is this a library I add to my project, or more of a learning resource?It's a reference collection rather than a drop-in library: the README shows how to compile and run each implementation on its own, so you read the code and copy what you need.
How do I compile and run an implementation? Do I need Bazel?You need JDK 8 or newer. Bazel is the recommended build system for running algorithms and tests, but you can skip it and compile any file with plain javac into a classes folder, then run it with java.
Does it tell you the time complexity of each algorithm?Yes — nearly every entry lists its complexity, like O(Elog(V)) for Dijkstra or O(nlog(n)) for the suffix array construction.
Is the project still being updated?It dates back to 2017 and is not archived, and GitHub Actions workflows (main.yml, readme-url-checker.yml) are set up in the repo.
Can I copy the code into my own project?Yes — the project is MIT licensed, so you can use, modify and redistribute the implementations, including in commercial work.
Size
1.2 GB
Stars
18.8K
Updated
CommitJun 23
Age
9y
Commits · 90 Days