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#
# Clone the repository
git clone https://github.com/aalhour/C-Sharp-Algorithms.git
cd C-Sharp-Algorithms
# Build and test
dotnet build
dotnet testRequirements: .NET 10.0 SDK or later
This project started as interview prep and evolved into a comprehensive reference implementation of classic computer science data structures and algorithms. Every component is:
- Educational — Clear, readable implementations with documentation
- Tested — 623+ unit tests ensuring correctness
- Modular — Use only what you need
| Project | Description |
|---|---|
Algorithms |
Sorting, searching, graph algorithms, and more |
DataStructures |
Lists, trees, heaps, hash tables, graphs |
UnitTest |
Comprehensive test coverage |
Lists & Collections
| Structure | Description |
|---|---|
| ArrayList | Dynamic array with auto-resizing |
| Stack | LIFO collection |
| Queue | FIFO collection |
| SLinkedList | Singly-linked list |
| DLinkedList | Doubly-linked list |
| SkipList | Probabilistic balanced structure |
| CircularBuffer | Fixed-size circular queue |
Heaps & Priority Queues
| Structure | Description |
|---|---|
| BinaryMinHeap | Min-heap using binary tree |
| BinaryMaxHeap | Max-heap using binary tree |
| BinomialMinHeap | Binomial heap (min) |
| MinPriorityQueue | Priority queue (min) |
| KeyedPriorityQueue | Key-value priority queue |
Hash Tables
| Structure | Description |
|---|---|
| ChainedHashTable | Separate chaining collision resolution |
| CuckooHashTable | Cuckoo hashing |
| OpenScatterHashTable | Linear probing |
| OpenAddressingHashTable | Open addressing with double hashing |
Hashing Functions: PrimeHashingFamily ・ UniversalHashingFamily
Trees
Search Trees
| Structure | Description |
|---|---|
| BinarySearchTree | Classic BST (Map version) |
| AugmentedBinarySearchTree | BST with subtree counts |
| TernarySearchTree | For string keys |
Self-Balancing Trees
| Structure | Description |
|---|---|
| AVLTree | Height-balanced BST |
| RedBlackTree | Color-balanced BST (Map version) |
| BTree | B-tree for disk-based storage |
Prefix Trees
| Structure | Description |
|---|---|
| Trie | Prefix tree for strings |
| TrieMap | Associative prefix tree |
Graphs
| Type | Sparse | Dense |
|---|---|---|
| Undirected | UndirectedSparseGraph | UndirectedDenseGraph |
| Undirected Weighted | UndirectedWeightedSparseGraph | UndirectedWeightedDenseGraph |
| Directed | DirectedSparseGraph | DirectedDenseGraph |
| Directed Weighted | DirectedWeightedSparseGraph | DirectedWeightedDenseGraph |
Also: CliqueGraph
Sorted Collections
| Structure | Description |
|---|---|
| SortedList | Always-sorted list |
| SortedDictionary | Sorted key-value store |
Sorting (16 algorithms)
| Algorithm | Type | Complexity |
|---|---|---|
| QuickSort | Divide & Conquer | O(n log n) avg |
| MergeSort | Divide & Conquer | O(n log n) |
| HeapSort | Selection | O(n log n) |
| InsertionSort | Insertion | O(n²) |
| SelectionSort | Selection | O(n²) |
| BubbleSort | Exchange | O(n²) |
| ShellSort | Insertion | O(n log² n) |
| CombSort | Exchange | O(n²) |
| CountingSort | Non-comparison | O(n + k) |
| LSD RadixSort | Non-comparison | O(nk) |
| BucketSort | Distribution | O(n + k) |
| BSTSort | Tree-based | O(n log n) |
| CycleSort | In-place | O(n²) |
| GnomeSort | Exchange | O(n²) |
| OddEvenSort | Exchange | O(n²) |
| PigeonHoleSort | Distribution | O(n + k) |
Graph Algorithms
Traversal
Shortest Paths
- Dijkstra — Single-source, non-negative weights
- Dijkstra All-Pairs — All pairs shortest paths
- Bellman-Ford — Handles negative weights
- BFS Shortest Paths — Unweighted graphs
Applications
Trees, Strings & Numeric
Tree Traversal
- Recursive Walker — Preorder, Inorder, Postorder
- Iterative Walker — Stack-based traversal
String Algorithms
- Permutations & Anagrams
- Edit Distance (Levenshtein)
Numeric
Visualization
Searching
See TODO.md for planned additions. Highlights:
- Data Structures: Bloom Filters, Fibonacci Heaps, Disjoint Sets, Suffix Trees
- Algorithms: A* Search, Minimum Spanning Trees, String Matching (KMP, Boyer-Moore)
Contributions welcome! Please read the Contribution Guidelines first.
This project is licensed under the MIT License.