Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexprut/algo
π Classic Algorithms and Data Structures implemented in Java
https://github.com/alexprut/algo
algorithm algorithms data-structures java
Last synced: 2 months ago
JSON representation
π Classic Algorithms and Data Structures implemented in Java
- Host: GitHub
- URL: https://github.com/alexprut/algo
- Owner: alexprut
- License: mit
- Created: 2018-10-03T23:01:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T10:53:46.000Z (8 months ago)
- Last Synced: 2024-05-07T11:48:14.721Z (8 months ago)
- Topics: algorithm, algorithms, data-structures, java
- Language: Java
- Homepage:
- Size: 583 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Classic Algorithms and Data Structures implemented in Java
[![Code Style](https://img.shields.io/badge/code%20style-google-green.svg?style=flat-square)](https://google.github.io/styleguide/javaguide.html)
[![MIT](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/alexprut/Algo/blob/master/LICENSE)
![Build Status](https://github.com/alexprut/Algo/actions/workflows/build.yml/badge.svg)
[![GitHub release](https://img.shields.io/github/release/alexprut/Algo.svg)](https://github.com/alexprut/Algo/releases)
[![Maven Central](https://img.shields.io/maven-central/v/com.alexprut/algo.svg)](https://search.maven.org/artifact/com.alexprut/algo)
Algorithms
==========|Algorithm|Worst-case time complexity|Average-case time complexity|Best-case time complexity|Auxiliary space complexity|
|:---|:---|:---|:---|:---|
|[Insertion Sort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/InsertionSort.java)|Ξ(n^2)|Ξ(n^2)|O(n)|-|
|[BubbleSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/BubbleSort.java)|O(n^2)|O(n^2)|O(n)|-|
|[MergeSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/MergeSort.java)|Ξ(nlogn)|Ξ(nlogn)|Ξ(nlogn)|-|
|[HeapSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/MaxHeap.java#L82)|Ξ(nlogn)|-|-|-|
|[QuickSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/QuickSort.java)|Ξ(n^2)|Ξ(nlogn)|Ξ(nlogn)|-|
|[CountingSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/CountingSort.java)|Ξ(k + n)|Ξ(k + n)|Ξ(n)|Ξ(n)|
|[RadixSort](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/sorting/RadixSort.java)|Ξ(d(k + n))|Ξ(d(k + n))|Ξ(n)|-|
|[Floyd-Warshall](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/graph/FloydWarshall.java)|Ξ(V^3)|Ξ(V^3)|Ξ(V^3)|Ξ(V^2)|
|[Kruskal](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/graph/mst/Kruskal.java)|O(\|E\|log\|V\|)|-|-|-|
|[Prim](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/graph/mst/Prim.java)|O(\|E\| + \|V\|log\|V\||-|-|-|
|[BellmanβFord](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/graph/BellmanFord.java)|Ξ(\|E\|\|V\|)|-|-|Ξ(V)|
|[Dijkstra](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/graph/Dijkstra.java)|O(\|E\| + \|V\|log\|V\|)|-|-|-|
|[Maximum SubArray](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/MaximumSubArray.java)|Ξ(n)|Ξ(n)|Ξ(n)|Ξ(1)|
|[Knuth-Morris-Pratt](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/KnuthMorrisPratt.java)|Ξ(n + m)|Ξ(n)|Ξ(n)|Ξ(n)|
|[Rabin-Karp](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/RabinKarp.java)|Ξ((n - m + 1)m)|Ξ(n)|Ξ(n)|-|
|[Greatest common divisor (GCD)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/math/Math.java#L13)|-|-|-|-|
|[Binary Search](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/search/BinarySearch.java)|O(nlogn)|O(nlogn)|O(1)|Ξ(1)|
|[Breadth First Search (BFS)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/search/BreadthFirstSearch.java#L43)|O(\|E\|+\|V\|)|O(\|E\|+\|V\|)|-|-|
|[Depth First Search (DFS)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/search/DepthFirstSearch.java#L10)|O(\|E\|+\|V\|)|O(\|E\|+\|V\|)|-|-|
|[Topological Sort (DFS)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/algorithms/search/DepthFirstSearch.java#L91)|O(\|E\|+\|V\|)|O(\|E\|+\|V\|)|-|-|
|[Longest Increasing Subsequence (LIS)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/Utils.java#L98)|Ξ(n^2)|-|-|Ξ(n)|
|[Longest Common Subsequence (LCS)](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/Utils.java#L128)|Ξ(n^2)|-|-|Ξ(n^2)|Data Structures
===============
|Data Structure|Methods|
|--------------|-------|
|[Max Heap](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/MaxHeap.java)|```max()``` - Ξ(1), ```extractMax()``` - O(nlogn), ```increaseKey()``` - O(logn), ```insert()``` - O(logn), ```heapify()``` - O(logn), ```heapsort()``` - O(nlogn)|
|[Min Heap](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/MinHeap.java)|```min()``` - Ξ(1), ```extractMin()``` - O(nlogn), ```insert()``` - O(logn), ```heapify()``` - O(logn), ```heapsort()``` - O(nlogn)|
|[MinMax Heap](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/MinMaxHeap.java)|```min()``` - Ξ(1), ```max()``` - Ξ(1), ```extractMin()``` - O(nlogn), ```extractMax()``` - O(nlogn), ```insert()``` - O(logn), ```heapify()``` - O(logn)|
|[Disjoint Set](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/DisjointSet.java)|```makeSet()``` - Ξ(1), ```findSet()``` - Ξ(1), ```union()``` - Ξ(1)|
|[Trie](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/Trie.java)|```insert()``` - O(\|s\|), ```search()``` - O(\|s\|), ```searchPrefix()``` - O(\|s\|), ```remove()``` - O(\|s\|), ```size()``` - O(1)|
|[Stack](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/Stack.java)|```push()``` - Ξ(1), ```pop()``` - Ξ(1), ```empty()``` - Ξ(1), ```size()``` - Ξ(1), ```peek()``` - Ξ(1)|
|[Queue](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/Queue.java)|```enqueue()``` - Ξ(1), ```dequeue()``` - Ξ(1), ```empty()``` - Ξ(1), ```size()``` - Ξ(1)|
|[Binary Search Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/BinarySearchTree.java)|```insert()``` - O(n), ```search()``` - O(n), ```delete()``` - O(n), ```contains()``` - O(n), ```minimum()``` - O(n), ```maximum()``` - O(n), ```size()``` - Ξ(1), ```successor()``` - O(logn), ```predecessor()``` - O(logn), ```preOrderVisit()``` - O(n), ```inOrderVisit()``` - O(n), ```postOrderVisit()``` - O(n)|
|[Double Linked List](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/DoubleLinkedList.java)|```insertFront()``` - Ξ(1), ```removeFront()``` - Ξ(1), ```insertBack()``` - Ξ(1), ```removeBack()``` - Ξ(1), ```head()``` - Ξ(1), ```size()``` - Ξ(1), ```search()``` - Ξ(n), ```remove()``` - Ξ(n)|
|[Linked List](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/LinkedList.java)|```insertFront()``` - Ξ(1), ```removeFront()``` - Ξ(1), ```head()``` - Ξ(1), ```size()``` - Ξ(1), ```search()``` - Ξ(n), ```remove()``` - Ξ(n)|
|[Skip List](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/SkipList.java)| ```insert()``` - Ξ(logn), ```remove()``` - Ξ(logn), ```search()``` - O(logn), ```size()``` - Ξ(1)|
|[Graph](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/Graph.java)|```buildAdjacencyMatrix()``` - Ξ(\|V\|^2), ```buildAdjacencyList()``` - Ξ(\|V\| + \|E\|), ```addEdge()``` - Ξ(1)|
|[Red-Black Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/RedBlackTree.java)|```insert()``` - O(logn), ```search()``` - O(logn), ```delete()``` - O(logn), ```minimum()``` - O(logn), ```maximum()``` - O(logn), ```successor()``` - O(logn), ```predecessor()``` - O(logn)|
|[Interval Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/IntervalTree.java)|```insert()``` - O(logn), ```search()``` - O(logn), ```find()``` - O(logn), ```findAll()``` - O(n), ```delete()``` - O(logn), ```minimum()``` - O(logn), ```maximum()``` - O(logn), ```successor()``` - O(logn), ```predecessor()``` - O(logn)|
|[Segment Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/SegmentTree.java)|```build()``` - O(n), ```update()``` - O(logn), ```search()``` - O(logn)|
|[AVL Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/AVLTree.java)|```insert()``` - O(logn), ```search()``` - O(logn), ```delete()``` - O(logn), ```minimum()``` - O(logn), ```maximum()``` - O(logn), ```successor()``` - O(logn)|
|[B-Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/BTree.java)|```insert()``` - O(th), ```search()``` - O(th), ```delete()``` - O(th), ```successor()``` - O(th), ```predecessor()``` - O(th)|
|[QuadTree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/QuadTree.java)|```insert()``` - O(logn), ```search()``` - O(logn), ```delete()``` - O(logn), ```size()``` - Ξ(1)|
|[Fibonacci Heap](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/FibonacciHeap.java)|```insert()``` - O(1), ```minimum()``` - O(1), ```extractMin()``` - O(logn), ```decreaseKey()``` - O(1), ```delete()``` - O(logn)|
|[Merkle Tree](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/MerkleTree.java)|```build()``` - O(n), ```verify()``` - O(logn), ```getProofPath()``` - O(logn)|
|[Bloom Filter](https://github.com/alexprut/Algo/blob/master/src/main/java/com/alexprut/algo/datastructures/BloomFilter.java)|```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:
```com.alexprut
algo
v0.4.0```
#### Requirements
- Gradle 8
- Java 11### 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](https://github.com/alexprut/Algo/blob/master/LICENSE).