C-Sharp-Algorithms

:books: :chart_with_upwards_trend: Plug-and-play class-library project of standard Data Structures and Algorithms in C#

View the Project on GitHub aalhour/C-Sharp-Algorithms


                                          o---o    |   |                                 
                                         /       --O---O--                               
                                        O          |   |                                 
                                         \       --O---O--                               
                                          o---o    |   |                                 


              O    o       o--o    o--o   o---o   o-O-o  o--O--o  o   o  o     o   o--o 
             / \   |      o       o    o  |   |     |       |     |   |  |\   /|  |     
            o---o  |      |  o-o  |    |  O--Oo     |       |     O---O  | \o/ |   o--o 
            |   |  |      o    |  o    o  |  \      |       |     |   |  |     |      | 
            o   o  O---o   o--o    o--o   o   \o  o-O-o     o     o   o  o     o  o---o 

A plug-and-play library of classic data structures and algorithms in C#

Build Status Release License Stars

.NET 10 Tests Data Structures Algorithms


⚡ Quick Start

# Clone the repository
git clone https://github.com/aalhour/C-Sharp-Algorithms.git
cd C-Sharp-Algorithms

# Build and test
dotnet build
dotnet test

Requirements: .NET 10.0 SDK or later


📖 About

This project started as interview prep and evolved into a comprehensive reference implementation of classic computer science data structures and algorithms. Every component is:

Project Structure

Project Description
Algorithms Sorting, searching, graph algorithms, and more
DataStructures Lists, trees, heaps, hash tables, graphs
UnitTest Comprehensive test coverage

📦 Data Structures

Lists & Collections | Structure | Description | |-----------|-------------| | [ArrayList](/C-Sharp-Algorithms/DataStructures/Lists/ArrayList.cs) | Dynamic array with auto-resizing | | [Stack](/C-Sharp-Algorithms/DataStructures/Lists/Stack.cs) | LIFO collection | | [Queue](/C-Sharp-Algorithms/DataStructures/Lists/Queue.cs) | FIFO collection | | [SLinkedList](/C-Sharp-Algorithms/DataStructures/Lists/SLinkedList.cs) | Singly-linked list | | [DLinkedList](/C-Sharp-Algorithms/DataStructures/Lists/DLinkedList.cs) | Doubly-linked list | | [SkipList](/C-Sharp-Algorithms/DataStructures/Lists/SkipList.cs) | Probabilistic balanced structure | | [CircularBuffer](/C-Sharp-Algorithms/DataStructures/Lists/CircularBuffer.cs) | Fixed-size circular queue |
Heaps & Priority Queues | Structure | Description | |-----------|-------------| | [BinaryMinHeap](/C-Sharp-Algorithms/DataStructures/Heaps/BinaryMinHeap.cs) | Min-heap using binary tree | | [BinaryMaxHeap](/C-Sharp-Algorithms/DataStructures/Heaps/BinaryMaxHeap.cs) | Max-heap using binary tree | | [BinomialMinHeap](/C-Sharp-Algorithms/DataStructures/Heaps/BinomialMinHeap.cs) | Binomial heap (min) | | [MinPriorityQueue](/C-Sharp-Algorithms/DataStructures/Heaps/MinPriorityQueue.cs) | Priority queue (min) | | [KeyedPriorityQueue](/C-Sharp-Algorithms/DataStructures/Heaps/KeyedPriorityQueue.cs) | Key-value priority queue |
Hash Tables | Structure | Description | |-----------|-------------| | [ChainedHashTable](/C-Sharp-Algorithms/DataStructures/Dictionaries/ChainedHashTable.cs) | Separate chaining collision resolution | | [CuckooHashTable](/C-Sharp-Algorithms/DataStructures/Dictionaries/CuckooHashTable.cs) | Cuckoo hashing | | [OpenScatterHashTable](/C-Sharp-Algorithms/DataStructures/Dictionaries/OpenScatterHashTable.cs) | Linear probing | | [OpenAddressingHashTable](/C-Sharp-Algorithms/DataStructures/Dictionaries/OpenAddressingHashTable.cs) | Open addressing with double hashing | **Hashing Functions:** [PrimeHashingFamily](/C-Sharp-Algorithms/DataStructures/Hashing/PrimeHashingFamily.cs) ・ [UniversalHashingFamily](/C-Sharp-Algorithms/DataStructures/Hashing/UniversalHashingFamily.cs)
Trees **Search Trees** | Structure | Description | |-----------|-------------| | [BinarySearchTree](/C-Sharp-Algorithms/DataStructures/Trees/BinarySearchTree.cs) | Classic BST ([Map version](/C-Sharp-Algorithms/DataStructures/Trees/BinarySearchTreeMap.cs)) | | [AugmentedBinarySearchTree](/C-Sharp-Algorithms/DataStructures/Trees/AugmentedBinarySearchTree.cs) | BST with subtree counts | | [TernarySearchTree](/C-Sharp-Algorithms/DataStructures/Trees/TernarySearchTree.cs) | For string keys | **Self-Balancing Trees** | Structure | Description | |-----------|-------------| | [AVLTree](/C-Sharp-Algorithms/DataStructures/Trees/AVLTree.cs) | Height-balanced BST | | [RedBlackTree](/C-Sharp-Algorithms/DataStructures/Trees/RedBlackTree.cs) | Color-balanced BST ([Map version](/C-Sharp-Algorithms/DataStructures/Trees/RedBlackTreeMap.cs)) | | [BTree](/C-Sharp-Algorithms/DataStructures/Trees/BTree.cs) | B-tree for disk-based storage | **Prefix Trees** | Structure | Description | |-----------|-------------| | [Trie](/C-Sharp-Algorithms/DataStructures/Trees/Trie.cs) | Prefix tree for strings | | [TrieMap](/C-Sharp-Algorithms/DataStructures/Trees/TrieMap.cs) | Associative prefix tree |
Graphs | Type | Sparse | Dense | |------|--------|-------| | **Undirected** | [UndirectedSparseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/UndirectedSparseGraph.cs) | [UndirectedDenseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/UndirectedDenseGraph.cs) | | **Undirected Weighted** | [UndirectedWeightedSparseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/UndirectedWeightedSparseGraph.cs) | [UndirectedWeightedDenseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/UndirectedWeightedDenseGraph.cs) | | **Directed** | [DirectedSparseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/DirectedSparseGraph.cs) | [DirectedDenseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/DirectedDenseGraph.cs) | | **Directed Weighted** | [DirectedWeightedSparseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/DirectedWeightedSparseGraph.cs) | [DirectedWeightedDenseGraph](/C-Sharp-Algorithms/DataStructures/Graphs/DirectedWeightedDenseGraph.cs) | Also: [CliqueGraph](/C-Sharp-Algorithms/DataStructures/Graphs/CliqueGraph.cs)
Sorted Collections | Structure | Description | |-----------|-------------| | [SortedList](/C-Sharp-Algorithms/DataStructures/SortedCollections/SortedList.cs) | Always-sorted list | | [SortedDictionary](/C-Sharp-Algorithms/DataStructures/SortedCollections/SortedDictionary.cs) | Sorted key-value store |

🔧 Algorithms

Sorting (16 algorithms) | Algorithm | Type | Complexity | |-----------|------|------------| | [QuickSort](/C-Sharp-Algorithms/Algorithms/Sorting/QuickSorter.cs) | Divide & Conquer | O(n log n) avg | | [MergeSort](/C-Sharp-Algorithms/Algorithms/Sorting/MergeSorter.cs) | Divide & Conquer | O(n log n) | | [HeapSort](/C-Sharp-Algorithms/Algorithms/Sorting/HeapSorter.cs) | Selection | O(n log n) | | [InsertionSort](/C-Sharp-Algorithms/Algorithms/Sorting/InsertionSorter.cs) | Insertion | O(n²) | | [SelectionSort](/C-Sharp-Algorithms/Algorithms/Sorting/SelectionSorter.cs) | Selection | O(n²) | | [BubbleSort](/C-Sharp-Algorithms/Algorithms/Sorting/BubbleSorter.cs) | Exchange | O(n²) | | [ShellSort](/C-Sharp-Algorithms/Algorithms/Sorting/ShellSorter.cs) | Insertion | O(n log² n) | | [CombSort](/C-Sharp-Algorithms/Algorithms/Sorting/CombSorter.cs) | Exchange | O(n²) | | [CountingSort](/C-Sharp-Algorithms/Algorithms/Sorting/CountingSorter.cs) | Non-comparison | O(n + k) | | [LSD RadixSort](/C-Sharp-Algorithms/Algorithms/Sorting/LSDRadixSorter.cs) | Non-comparison | O(nk) | | [BucketSort](/C-Sharp-Algorithms/Algorithms/Sorting/BucketSorter.cs) | Distribution | O(n + k) | | [BSTSort](/C-Sharp-Algorithms/Algorithms/Sorting/BinarySearchTreeSorter.cs) | Tree-based | O(n log n) | | [CycleSort](/C-Sharp-Algorithms/Algorithms/Sorting/CycleSorter.cs) | In-place | O(n²) | | [GnomeSort](/C-Sharp-Algorithms/Algorithms/Sorting/GnomeSorter.cs) | Exchange | O(n²) | | [OddEvenSort](/C-Sharp-Algorithms/Algorithms/Sorting/OddEvenSorter.cs) | Exchange | O(n²) | | [PigeonHoleSort](/C-Sharp-Algorithms/Algorithms/Sorting/PigeonHoleSorter.cs) | Distribution | O(n + k) |
Graph Algorithms **Traversal** - [Depth-First Search](/C-Sharp-Algorithms/Algorithms/Graphs/DepthFirstSearcher.cs) - [Breadth-First Search](/C-Sharp-Algorithms/Algorithms/Graphs/BreadthFirstSearcher.cs) **Shortest Paths** - [Dijkstra](/C-Sharp-Algorithms/Algorithms/Graphs/DijkstraShortestPaths.cs) — Single-source, non-negative weights - [Dijkstra All-Pairs](/C-Sharp-Algorithms/Algorithms/Graphs/DijkstraAllPairsShortestPaths.cs) — All pairs shortest paths - [Bellman-Ford](/C-Sharp-Algorithms/Algorithms/Graphs/BellmanFordShortestPaths.cs) — Handles negative weights - [BFS Shortest Paths](/C-Sharp-Algorithms/Algorithms/Graphs/BreadthFirstShortestPaths.cs) — Unweighted graphs **Applications** - [Cycle Detection](/C-Sharp-Algorithms/Algorithms/Graphs/CyclesDetector.cs) - [Topological Sort](/C-Sharp-Algorithms/Algorithms/Graphs/TopologicalSorter.cs) - [Connected Components](/C-Sharp-Algorithms/Algorithms/Graphs/ConnectedComponents.cs) - [Bipartite Coloring](/C-Sharp-Algorithms/Algorithms/Graphs/BipartiteColoring.cs)
Trees, Strings & Numeric **Tree Traversal** - [Recursive Walker](/C-Sharp-Algorithms/Algorithms/Trees/BinaryTreeRecursiveWalker.cs) — Preorder, Inorder, Postorder - [Iterative Walker](/C-Sharp-Algorithms/Algorithms/Trees/BinaryTreeIterativeWalker.cs) — Stack-based traversal **String Algorithms** - [Permutations & Anagrams](/C-Sharp-Algorithms/Algorithms/Strings/Permutations.cs) - [Edit Distance](/C-Sharp-Algorithms/Algorithms/Strings/EditDistance.cs) (Levenshtein) **Numeric** - [Binomial Coefficients](/C-Sharp-Algorithms/Algorithms/Numeric/BinomialCoefficients.cs) - [Catalan Numbers](/C-Sharp-Algorithms/Algorithms/Numeric/CatalanNumbers.cs) - [Greatest Common Divisor](/C-Sharp-Algorithms/Algorithms/Numeric/GreatestCommonDivisor.cs) - [Sieve of Eratosthenes](/C-Sharp-Algorithms/Algorithms/Numeric/SieveOfEratosthenes.cs) - [Sieve of Atkin](/C-Sharp-Algorithms/Algorithms/Numeric/SieveOfAtkin.cs) **Visualization** - [Tree Drawer](/C-Sharp-Algorithms/DataStructures/Trees/TreeDrawer.cs)
Searching - [Binary Search](/C-Sharp-Algorithms/Algorithms/Search/BinarySearcher.cs)

🚀 Roadmap

See TODO.md for planned additions. Highlights:


🤝 Contributing

Contributions welcome! Please read the Contribution Guidelines first.


📄 License

This project is licensed under the MIT License.