Please don't take effort to create pull requests for new algorithms/data structures. This is just a curiosity driven personal hobby and was originally not intented to be a library. Feel free fork and modify to fit your need if that's what you are looking for. You can however open issues/fix bugs with pull requests here, I would be happy to take a look when I get time.
Various important computer science algorithms generically implemented in C#.
Install by nuget
For beta releases on beta branch
Install-Package Advanced.Algorithms -Pre
Not a stable release yet.
Supports
- .Net Standard 1.0 or above
- .Net Framework 4.0 or above
- Array List (dynamic array) (Implementation | Tests)
- Skip List (Implementation | Tests)
- HashSet (using Separate Chaining optionally Open Address Linear Probing) (Implementation | Tests)
- Tree HashSet (Implementation | Tests)
- Dictionary (using Separate Chaining optionally Open Address Linear Probing) (Implementation | Tests)
- Tree Dictionary (Implementation | Tests)
- Stack (using Dynamic Array and optionally using Singly Linked List) (Implementation | Tests)
- Queue (using Dynamic Array and optionally using Doubly Linked List) (Implementation | Tests)
- Min Priority Queue (Implementation | Tests)
- Max Priority Queue (Implementation | Tests)
- Singly linked list (Implementation | Tests)
- Doubly linked list (Implementation | Tests)
- Circular linked list (Implementation | Tests)
- Binary Min Heap (Implementation | Tests)
- d-ary Min Heap (Implementation | Tests)
- Binomial Min Heap (Implementation | Tests)
- Fibornacci Min Heap (Implementation | Tests)
- Pairing Min Heap (Implementation | Tests)
- Binary Max Heap (Implementation | Tests)
- d-ary Max Heap (Implementation | Tests)
- Binomial Max Heap (Implementation | Tests)
- Fibornacci Max Heap (Implementation | Tests)
- Pairing Max Heap (Implementation | Tests)
Note: It is observed that among the implementations here in practice, with the exclusion of DecrementKey/IncrementKey operation regular Binary Heap & d-ary Heap outperforms other in theory superiors. Likely because it don't have pointer juggling overhead and hey arrays are faster!
- Tree (Implementation | Tests)
- Binary Tree (Implementation | Tests)
- Binary Search Tree (Implementation | Tests)
- AVL Tree (Implementation | Tests)
- Red Black Tree (Implementation | Tests)
- Splay Tree (Implementation | Tests)
- Treap Tree (Implementation | Tests)
- B Tree (Implementation | Tests)
- B+ Tree (Implementation | Tests)
- Segment Tree (Implementation | Tests)
- Binary Indexed Tree (Fenwick tree) (Implementation | Tests)
- Multi-dimensional Interval Tree (Implementation | Tests) using nested Red-black tree
- Multi-dimensional Kd Tree (Implementation | Tests) for range and nearest neigbour queries
- Multi-dimensional Range Tree (Implementation | Tests) using nested Red-black tree
- R-Tree (Implementation | Tests)
TODO: Support multi-dimentional segment tree & binary indexed tree.
- Prefix Tree (Trie) (Implementation | Tests)
- Suffix Tree (Implementation | Tests)
- Ternary Search Tree (Implementation | Tests)
TODO: implement trie compression.
- Disjoint Set (Implementation | Tests)
- Sparse Set (Implementation | Tests)
- Bloom Filter (Implementation | Tests)
- Graph (Implementation | Tests)
- Weighted Graph (Implementation | Tests)
- DiGraph (Implementation | Tests)
- Weighted DiGraph (Implementation | Tests)
- Graph (Implementation | Tests)
- Weighted Graph (Implementation | Tests)
- DiGraph (Implementation | Tests)
- Weighted DiGraph (Implementation | Tests)
- Tarjan's Articulation Points Finder (Implementation | Tests)
- Tarjan's Bridge Finder (Implementation | Tests)
- Kosaraju's Strongly Connected Component Finder (Implementation | Tests)
- Tarjan's Strongly Connected Component Finder (Implementation | Tests)
- Tarjan's BiConnected Graph Tester (Implementation | Tests)
- M-Coloring (Implementation | Tests)
- Min Vertex Cover (Implementation | Tests)
- Ford-Fulkerson algorithm (Implementation | Tests)
- Edmonds Karp's improvement (Implementation | Tests) on Ford-Fulkerson algorithm
- Push Relabel algorithm (Implementation | Tests)
- Bellman-Ford algorithm (Implementation | Tests)
- Dijikstra's algorithm (Implementation | Tests) using Fibornacci Heap.
- Floyd-Warshall algorithm (Implementation | Tests)
- Johnson's algorithm (Implementation | Tests)
- Travelling Salesman Problem (Implementation | Tests)
- Max Bipartite Matching (Implementation | Tests) using Edmonds Karp's improved Ford Fulkerson Max Flow algorithm
- Max Bipartite Matching (Implementation | Tests) using Hopcroft Karp algorithm
- Minimum Cut (Implementation | Tests) using Edmonds Karp's improved Ford Fulkerson Max Flow algorithm
- Depth First (Implementation | Tests)
- Breadth First (Implementation | Tests)
- Bi-Directional (Implementation | Tests)
- Depth First Method (Implementation | Tests)
- Kahn's algorithm (Implementation | Tests)
- Kruskal's algorithm (Implementation | Tests) using Merge Sort and Disjoint Set
- Prim's algorithm (Implementation | Tests)
- Manacher's algorithm for linear time longest Palindrome (Implementation | Tests)
- Rabin-Karp string search (Implementation | Tests)
- Knuth–Morris–Pratt (KMP) string search (Implementation | Tests)
- Z algorithm for string search (Implementation | Tests)
- Huffman Coding (Implementation | Tests)
- Binary Search (Implementation | Tests)
- Quick select for kth smallest/largest in unordered collection using median of medians (Implementation | Tests)
- Majority element using Boyer-Moore voting algorithm (Implementation | Tests)
- Bubble Sort (Implementation | Tests)
- Insertion Sort (Implementation | Tests)
- Selection Sort (Implementation | Tests)
- Shell Sort (Implementation | Tests)
- Tree Sort (Implementation | Tests)
- Quick Sort (Implementation | Tests)
- Heap Sort (Implementation | Tests)
- Merge Sort (Implementation | Tests)
- Bucket Sort (Implementation | Tests)
- Radix Sort (Implementation | Tests)
- Counting Sort (Implementation | Tests)
Note: On a decent desktop, in given implementations here for +ive random input integers, the clear winner is counting sort (~0.1 seconds to sort 1 million integers) followed by Radix Sort (~0.4 seconds). Merge Sort, Heap Sort, Quick Sort & Bucket Sort are all winners for +ive & -ive random integer inputs. Tree sort has pointer juggling overhead on backing Red-Black Tree, so performs 8 times slower than Merge Sort in practice. Bubble Sort, Insertion Sort, Selection Sort & Shell Sort are among the worst for random input as observed from results.
- Permutations (Implementation | Tests)
- Combinations (Implementation | Tests)
- Subsets (Implementation | Tests)
- Circular Queue (Ring Buffer) (Implementation | Tests)
- Consistant Hash (Implementation | Tests)
- LRU Cache (Implementation | Tests)
- Check Primality (Implementation | Tests)
- Generate Primes using Sieve of Eratosthenes (Implementation | Tests)
- Fast Exponentiation (Implementation | Tests)
- Convex hull using Gift wrapping algorithm (Implementation | Tests)
- Line intersection (Implementation | Tests)
- Closest point pair (Implementation | Tests)
- Check if given point inside polygon (Implementation | Tests)
- Rectangle intersection (Implementation | Tests)
- Point Rotation (Implementation | Tests)
- Line interesections with Bentley-Ottmann sweep line algorithm using Red-Black tree and binary minimum heap (Implementation | Tests)
- Base conversion (Implementation | Tests)
- Calculate Logarithm (base 2 & 10) (Implementation | Tests)
- GCD (Implementation | Tests)