Data Structures Implemented in TheAlgorithms/Java: A Comprehensive Catalog

The TheAlgorithms/Java repository contains production-quality implementations of 40+ data structures ranging from fundamental stacks and queues to advanced self-balancing trees, graph algorithms, distributed systems primitives (CRDTs), and specialized caches, all organized under src/main/java/com/thealgorithms/datastructures/.

The TheAlgorithms/Java repository is one of the most comprehensive open-source collections of computer science algorithms and data structures written in idiomatic Java. Whether you are preparing for technical interviews or researching implementation patterns, this codebase offers fully documented, runnable examples of both classic and modern data structures. This guide catalogs every major implementation category with specific file paths and usage examples derived directly from the source.

Tree-Based Data Structures

The src/main/java/com/thealgorithms/datastructures/trees/ directory contains sophisticated tree implementations spanning basic search trees to spatial indexing structures.

Binary Search Trees

The repository provides two pedagogical approaches to BSTs in [BSTIterative.java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTIterative.java) and [BSTRecursive.java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/trees/BSTRecursive.java). Both implement standard operations—insert, search, and delete—with the same API but different traversal strategies.

Self-Balancing Trees

For O(log n) guaranteed performance, the repository includes:

Advanced Tree Structures

Specialized trees for specific computational problems include:

AVL Tree Usage Example:

import com.thealgorithms.datastructures.trees.AVLTree;

public class AVLTreeDemo {
    public static void main(String[] args) {
        AVLTree tree = new AVLTree();
        tree.insert(30);
        tree.insert(20);
        tree.insert(40);
        tree.insert(10);
        tree.insert(25);
        
        System.out.println("Contains 25? " + tree.search(25)); // true
        tree.delete(20);
        System.out.println("Balance factors: " + tree.returnBalance());
    }
}

Graph Data Structures

The src/main/java/com/thealgorithms/datastructures/graphs/ package provides both graph representations and classic algorithms.

Graph Representations

Graph Algorithms

The repository implements canonical algorithms including:

Linear Data Structures

Stack Implementations

Located in src/main/java/com/thealgorithms/datastructures/stacks/, the repository provides the [Stack.java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/stacks/Stack.java) generic interface with multiple backing implementations:

Stack Usage Example:

import com.thealgorithms.datastructures.stacks.Stack;
import com.thealgorithms.datastructures.stacks.StackArrayList;

public class StackDemo {
    public static void main(String[] args) {
        Stack<Integer> stack = new StackArrayList<>();
        stack.push(5);
        stack.push(10);
        stack.push(15);
        System.out.println("Top element: " + stack.peek()); // 15
        System.out.println("Popped: " + stack.pop());      // 15
        System.out.println("Size: " + stack.size());       // 2
    }
}

Queue Implementations

The src/main/java/com/thealgorithms/datastructures/queues/ directory contains diverse queue variants:

Queue Usage Example:

import com.thealgorithms.datastructures.queues.QueueByTwoStacks;

public class QueueDemo {
    public static void main(String[] args) {
        QueueByTwoStacks<Integer> q = new QueueByTwoStacks<>();
        q.enqueue(1);
        q.enqueue(2);
        q.enqueue(3);
        System.out.println(q.dequeue()); // 1
        System.out.println(q.peek());    // 2
        System.out.println(q.size());    // 2
    }
}

Linked List Variants

The src/main/java/com/thealgorithms/datastructures/lists/ package provides:

Advanced and Specialized Structures

Dynamic Arrays

The [DynamicArray.java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java) class in src/main/java/com/thealgorithms/datastructures/dynamicarray/ implements a resizable array with automatic capacity doubling and iterator support.

import com.thealgorithms.datastructures.dynamicarray.DynamicArray;

public class DynamicArrayDemo {
    public static void main(String[] args) {
        DynamicArray<String> arr = new DynamicArray<>();
        arr.add("Alice");
        arr.add("Bob");
        arr.put(5, "Eve");  // auto-expands
        System.out.println(arr.get(5));  // Eve
        arr.remove(0);
    }
}

Disjoint-Set Union (Union-Find)

Located in src/main/java/com/thealgorithms/datastructures/disjointsetunion/, these structures manage partitioned sets with near-constant time union and find operations:

Conflict-Free Replicated Data Types (CRDTs)

For distributed systems, the src/main/java/com/thealgorithms/datastructures/crdt/ package implements eventually consistent data structures:

Cache Implementations

The src/main/java/com/thealgorithms/datastructures/caches/ directory provides production-ready eviction policies:

LRU Cache Usage Example:

import com.thealgorithms.datastructures.caches.LRUCache;

public class LRUCacheDemo {
    public static void main(String[] args) {
        LRUCache<Integer, String> cache = new LRUCache<>(3);
        cache.put(1, "One");
        cache.put(2, "Two");
        cache.put(3, "Three");
        cache.get(2);  // marks as recent
        cache.put(4, "Four");  // evicts key 1
        System.out.println(cache);  // contains 2,3,4
    }
}

Circular Buffers

The [CircularBuffer.java](https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/datastructures/buffers/CircularBuffer.java) class in src/main/java/com/thealgorithms/datastructures/buffers/ implements a fixed-size ring buffer for streaming data scenarios.

Summary

  • TheAlgorithms/Java organizes 40+ data structure implementations under src/main/java/com/thealgorithms/datastructures/ with consistent package hierarchies for trees, graphs, lists, stacks, and queues.
  • Tree structures range from basic BSTs to advanced spatial indices like KD-Trees and Quad-Trees, including self-balancing AVL and Red-Black trees with rotation-based rebalancing.
  • Graph support includes both adjacency list representations in UndirectedAdjacencyListGraph.java and comprehensive algorithm implementations including Dijkstra, A*, MST, and Max Flow.
  • Linear collections offer multiple backing strategies (array, linked list, two-stack) for stacks and queues, plus specialized variants like Deques, Priority Queues, and Skip Lists.
  • Advanced structures cover Dynamic Arrays with iterator support, Union-Find with path compression, distributed systems primitives (CRDTs), and cache eviction policies (LRU, LFU, MRU).

Frequently Asked Questions

What tree data structures are available in TheAlgorithms/Java?

The repository implements ten distinct tree structures in src/main/java/com/thealgorithms/datastructures/trees/, including Binary Search Trees (iterative and recursive), self-balancing AVL and Red-Black trees, Segment Trees for range queries, Fenwick Trees for prefix sums, Tries for string matching, KD-Trees for spatial data, Quad-Trees for 2D indexing, Splay Trees with self-adjusting properties, and randomized Treaps.

Does TheAlgorithms/Java include production-ready cache implementations?

Yes, the src/main/java/com/thealgorithms/datastructures/caches/ package contains fully functional cache implementations with O(1) operations, including LRU (Least Recently Used), LFU (Least Frequently Used), MRU (Most Recently Used), FIFO, and LIFO eviction policies, suitable for understanding cache semantics or adapting into production systems.

What distributed systems data structures are implemented?

The repository includes Conflict-Free Replicated Data Types (CRDTs) in src/main/java/com/thealgorithms/datastructures/crdt/, specifically Two-P-Sets, PN-Counters for distributed counting, OR-Sets for observed-remove semantics, and LWW-Element-Sets using last-writer-wins resolution, enabling eventually consistent distributed state management.

How are graph algorithms organized in the repository?

Graph algorithms are separated from representations in src/main/java/com/thealgorithms/datastructures/graphs/, with UndirectedAdjacencyListGraph.java providing the base structure, while standalone classes implement Dijkstra's algorithm, A* search, Bellman-Ford, Prim's and Kruskal's MST algorithms, Tarjan's SCC detection, and Ford-Fulkerson maximum flow.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →