Algo
Algo copied to clipboard
π Classic Algorithms and Data Structures implemented in Java
Algorithms
Algorithm | Worst-case time complexity | Average-case time complexity | Best-case time complexity | Auxiliary space complexity |
---|---|---|---|---|
Insertion Sort | Ξ(n^2) | Ξ(n^2) | O(n) | - |
BubbleSort | O(n^2) | O(n^2) | O(n) | - |
MergeSort | Ξ(nlogn) | Ξ(nlogn) | Ξ(nlogn) | - |
HeapSort | Ξ(nlogn) | - | - | - |
QuickSort | Ξ(n^2) | Ξ(nlogn) | Ξ(nlogn) | - |
CountingSort | Ξ(k + n) | Ξ(k + n) | Ξ(n) | Ξ(n) |
RadixSort | Ξ(d(k + n)) | Ξ(d(k + n)) | Ξ(n) | - |
Floyd-Warshall | Ξ(V^3) | Ξ(V^3) | Ξ(V^3) | Ξ(V^2) |
Kruskal | O(|E|log|V|) | - | - | - |
Prim | O(|E| + |V|log|V| | - | - | - |
BellmanβFord | Ξ(|E||V|) | - | - | Ξ(V) |
Dijkstra | O(|E| + |V|log|V|) | - | - | - |
Maximum SubArray | Ξ(n) | Ξ(n) | Ξ(n) | Ξ(1) |
Knuth-Morris-Pratt | Ξ(n + m) | Ξ(n) | Ξ(n) | Ξ(n) |
Rabin-Karp | Ξ((n - m + 1)m) | Ξ(n) | Ξ(n) | - |
Greatest common divisor (GCD) | - | - | - | - |
Binary Search | O(nlogn) | O(nlogn) | O(1) | Ξ(1) |
Breadth First Search (BFS) | O(|E|+|V|) | O(|E|+|V|) | - | - |
Depth First Search (DFS) | O(|E|+|V|) | O(|E|+|V|) | - | - |
Topological Sort (DFS) | O(|E|+|V|) | O(|E|+|V|) | - | - |
Longest Increasing Subsequence (LIS) | Ξ(n^2) | - | - | Ξ(n) |
Longest Common Subsequence (LCS) | Ξ(n^2) | - | - | Ξ(n^2) |
Data Structures
Data Structure | Methods |
---|---|
Max Heap | max() - Ξ(1), extractMax() - O(nlogn), increaseKey() - O(logn), insert() - O(logn), heapify() - O(logn), heapsort() - O(nlogn) |
Min Heap | min() - Ξ(1), extractMin() - O(nlogn), insert() - O(logn), heapify() - O(logn), heapsort() - O(nlogn) |
MinMax Heap | min() - Ξ(1), max() - Ξ(1), extractMin() - O(nlogn), extractMax() - O(nlogn), insert() - O(logn), heapify() - O(logn) |
Disjoint Set | makeSet() - Ξ(1), findSet() - Ξ(1), union() - Ξ(1) |
Trie | insert() - O(|s|), search() - O(|s|), searchPrefix() - O(|s|), remove() - O(|s|), size() - O(1) |
Stack | push() - Ξ(1), pop() - Ξ(1), empty() - Ξ(1), size() - Ξ(1), peek() - Ξ(1) |
Queue | enqueue() - Ξ(1), dequeue() - Ξ(1), empty() - Ξ(1), size() - Ξ(1) |
Binary Search Tree | insert() - O(n), search() - O(n), delete() - O(n), contains() - O(n), minimum() - O(n), maximum() - O(n), size() - Ξ(1), successor() - O(n), preOrderVisit() - O(n), inOrderVisit() - O(n), postOrderVisit() - O(n) |
Double Linked List | insertFront() - Ξ(1), removeFront() - Ξ(1), insertBack() - Ξ(1), removeBack() - Ξ(1), head() - Ξ(1), size() - Ξ(1) |
Linked List | insertFront() - Ξ(1), removeFront() - Ξ(1), head() - Ξ(1), size() - Ξ(1) |
Graph | buildAdjacencyMatrix() - Ξ(|V|^2), buildAdjacencyList() - Ξ(|V| + |E|), addEdge() - Ξ(1) |
Red-Black Tree | insert() - O(logn), search() - O(logn), delete() - O(logn), minimum() - O(logn), maximum() - O(logn), successor() - O(logn) |
Interval Tree | insert() - O(logn), search() - O(logn), find() - O(logn), findAll() - O(n), delete() - O(logn), minimum() - O(logn), maximum() - O(logn), successor() - O(logn) |
Segment Tree | build() - O(n), update() - O(logn), search() - O(logn) |
AVL Tree | insert() - O(logn), search() - O(logn), delete() - O(logn), minimum() - O(logn), maximum() - O(logn), successor() - O(logn) |
B-Tree | insert() - O(th), search() - O(th), delete() - O(th), successor() - O(th), predecessor() - O(th) |
Fibonacci Heap | insert() - O(1), minimum() - O(1), extractMin() - O(logn), decreaseKey() - O(1), delete() - O(logn) |
Merkle Tree | build() - O(n), verify() - O(logn), getProofPath() - O(logn) |
Bloom Filter | search() - O(k), insert() - O(k) |
Add to your build
To add a dependency using Gradle, use the following:
implementation 'com.alexprut:algo:v0.4.0'
To add a dependency using Gradle Kotlin DSL:
implementation("com.alexprut:algo:v0.4.0")
To add a dependency using Maven:
<dependency>
<groupId>com.alexprut</groupId>
<artifactId>algo</artifactId>
<version>v0.4.0</version>
</dependency>
Build
./gradlew clean build
Test
./gradlew test
Formatting style
./gradlew goJF
./gradlew verGJF
Generate Changelog
git-chglog v1.0.0..v2.0.0
License
Licensed under MIT.