williamfiset /algorithms

A collection of algorithms and data structures

★ 18,889⑂ 4,524
JavaCreated 2017-03-18
18,889
stars
+3+3
4,524
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

!README Checker


 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

 Running with Bazel (recommended)

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

Run a single algorithm like this:

bash
bazel run //src/main/java/com/williamfiset/algorithms/:


For instance:

bash
bazel run //src/main/java/com/williamfiset/algorithms/search:BinarySearch


Run all tests:

bash
bazel test //src/test/...


Run tests for a specific package:

bash
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

bash
cd Algorithms
mkdir classes


 Compile the algorithm

bash
javac -sourcepath src/main/java -d classes src/main/java/


 Run the algorithm

bash
java -cp classes 


 Example

bash
$ 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

- :movie_camera: Balanced Trees
  - AVL Tree (recursive)
  - Red Black Tree (recursive)
- :movie_camera: Binary Search Tree
- Splay Tree
- :movie_camera: Dynamic Array
  - Dynamic array (integer only, fast)
- :movie_camera: Fenwick Tree
  - Fenwick Tree (range query, point updates)
  - Fenwick Tree (range update, point query)
- Fibonacci Heap
- :movie_camera: Hashtable
  - Hashtable (double hashing)
  - Hashtable (linear probing)
  - Hashtable (quadratic probing)
  - Hashtable (separate chaining)
- :movie_camera: Linked List
- :movie_camera: Priority Queue
  - Min Binary Heap
  - Min Indexed Binary Heap (sorted key-value pairs, similar to hash-table)
  - Min D-Heap
  - :movie_camera: Min Indexed D-Heap (sorted key-value pairs, similar to hash-table)
- :movie_camera: Queue
  - Queue (integer only, fixed size, fast)
  - Queue (linked list, generic)
- Segment Tree
  - Segment tree (array based, compact)
  - Segment tree (pointer implementation)
- :movie_camera: Sparse Table
- :movie_camera: Stack
  - Stack (integer only, fixed size, fast)
  - Stack (linked list, generic)
  - Stack (array, generic)
- :movie_camera: Suffix Array
  - Suffix Array (O(n²logn) construction)
  - Suffix Array (O(nlog²(n)) construction)
  - Suffix Array (O(nlog(n)) cons

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON