A comprehensive collection of data structures and algorithms implemented in Java, designed for learning, reference, and reuse.
This library provides clean, generic implementations of fundamental data structures and algorithms
commonly encountered in computer science. All implementations use Java generics where applicable,
with elements constrained by Comparable<T> for ordering operations.
| Algorithm | Time Complexity (Best) | Time Complexity (Avg) | Time Complexity (Worst) | Space Complexity |
|---|---|---|---|---|
| Bubble Sort | O(n) | O(n^2) | O(n^2) | O(1) |
| Selection Sort | O(n^2) | O(n^2) | O(n^2) | O(1) |
| Insertion Sort | O(n) | O(n^2) | O(n^2) | O(1) |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(k) |
| Algorithm | Time Complexity (Best) | Time Complexity (Avg) | Time Complexity (Worst) | Space Complexity |
|---|---|---|---|---|
| Linear Search | O(1) | O(n) | O(n) | O(1) |
| Binary Search | O(1) | O(log n) | O(log n) | O(1) |
| Structure | Operations | Time Complexity |
|---|---|---|
| MinHeap | add, top, peek, remove, update, contains |
O(log n) insert/delete, O(1) peek/contains |
| MaxHeap | add, top, peek, remove, update, contains |
O(log n) insert/delete, O(1) peek/contains |
Both heap implementations support a configurable branching factor (2-10) and use an internal
index map for O(1) element lookup, enabling efficient remove() and update() operations.
| Structure | Description |
|---|---|
| Singly Linked List | Linear list with forward-only traversal |
| Doubly Linked List | Linear list with bidirectional traversal |
| Structure | Description |
|---|---|
| Binary Tree | Generic binary tree with level-order (BFS) insertion |
| Structure | Description |
|---|---|
| Stack | LIFO stack backed by LinkedList |
| LinkedListStack | Stack extending base Stack with linked list backend |
| Structure | Description |
|---|---|
| Priority Queue | Priority-based queue using ArrayList |
| Class | Description |
|---|---|
| StringUtils | String helpers: isEmpty, reverse, isPalindrome |
Before building the project, ensure you have the following installed:
- Java (JDK 11 or later)
- Maven (v3.x or later)
git clone https://github.com/mjbullman/java-library.git
cd java-library
mvn clean compile
Run all unit tests using JUnit 5:
mvn test
Run a specific test class:
mvn test -Dtest=BubbleSortTest
Run a specific test method:
mvn test -Dtest=BubbleSortTest#testBubbleSortIntegerArray
Run Checkstyle with Sun coding conventions:
mvn verify
src/
├── main/java/com/
│ ├── algorithms/
│ │ ├── graphs/ # Graph algorithms
│ │ ├── searching/ # Search algorithms
│ │ └── sorting/ # Sorting algorithms
│ ├── datastructures/
│ │ ├── heaps/ # Min and Max heap implementations
│ │ ├── linkedlists/ # Linked list variants
│ │ ├── queues/ # Queue implementations
│ │ ├── stacks/ # Stack implementations
│ │ └── trees/ # Tree implementations
│ ├── string/ # String utilities
│ └── utilities/ # General utilities
└── test/java/com/ # Unit tests (JUnit 5)
Feel free to fork this repository, raise issues, or submit pull requests. Contributions are welcome and encouraged under the terms of the project's license.
Please ensure that your contributions follow the project's coding standards and guidelines. After forking, clone your copy of the repository, create a branch for your work, and submit a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for details.