ACSL prep + general competitive programming. I run the CS club I founded at school, so I keep adding to this whenever I learn something new or prep a lesson. The KMP and trie implementations are probably the most useful ones I've written — ended up using them way outside of contest prep.
data-structures-and-algorithms/
├── src/
│ ├── sorting/
│ │ ├── quicksort.py # O(n log n) average, in-place
│ │ ├── mergesort.py # O(n log n) stable sort
│ │ ├── heapsort.py # O(n log n) heap-based
│ │ └── radix.py # O(nk) non-comparative
│ ├── trees/
│ │ ├── bst.py # Binary Search Tree
│ │ ├── avl.py # Self-balancing AVL Tree
│ │ └── segment_tree.py # Range query segment tree
│ ├── graphs/
│ │ ├── dijkstra.py # Single-source shortest path
│ │ ├── bfs_dfs.py # Breadth/depth-first search
│ │ ├── union_find.py # Disjoint Set Union (DSU)
│ │ └── topological_sort.py # Kahn's + DFS-based
│ ├── dp/
│ │ ├── knapsack.py # 0/1 Knapsack
│ │ ├── lcs.py # Longest Common Subsequence
│ │ ├── matrix_chain.py # Matrix chain multiplication
│ │ └── coin_change.py # Minimum coins / count ways
│ └── strings/
│ ├── kmp.py # Knuth-Morris-Pratt
│ ├── trie.py # Prefix trie
│ └── rabin_karp.py # Rolling hash search
├── contests/
│ └── acsl_solutions.py # ACSL-style problems with solutions
└── notebooks/
└── complexity_analysis.ipynb # Big O analysis with timings
| Category | What's covered |
|---|---|
| Sorting | QuickSort, MergeSort, HeapSort, Radix Sort |
| Trees | BST, AVL, Segment Tree, Fenwick Tree |
| Graphs | Dijkstra, BFS/DFS, Topological Sort, Union-Find |
| Dynamic Programming | Knapsack, LCS, Matrix Chain, Coin Change |
| String Algorithms | KMP, Trie, Rabin-Karp |
| ACSL Contests | LIFO/FIFO, prefix notation, recursion, boolean algebra |
git clone https://github.com/Bruh-Gang/data-structures-and-algorithms.git
cd data-structures-and-algorithmsfrom src.sorting.quicksort import quicksort
arr = [64, 34, 25, 12, 22, 11, 90]
print(quicksort(arr)) # [11, 12, 22, 25, 34, 64, 90]from src.graphs.dijkstra import dijkstra
graph = {
'A': [('B', 1), ('C', 4)],
'B': [('C', 2), ('D', 5)],
'C': [('D', 1)],
'D': []
}
print(dijkstra(graph, 'A')) # {'A': 0, 'B': 1, 'C': 3, 'D': 4}from src.dp.knapsack import knapsack_01
print(knapsack_01([2, 3, 4, 5], [3, 4, 5, 6], 8)) # 10| Algorithm | Best | Average | Worst | Space |
|---|---|---|---|---|
| QuickSort | O(n log n) | O(n log n) | O(n²) | O(log n) |
| MergeSort | O(n log n) | O(n log n) | O(n log n) | O(n) |
| HeapSort | O(n log n) | O(n log n) | O(n log n) | O(1) |
| Dijkstra | — | O((V+E) log V) | O((V+E) log V) | O(V) |
| KMP | O(n+m) | O(n+m) | O(n+m) | O(m) |
| Segment Tree (query) | O(log n) | O(log n) | O(log n) | O(n) |
ACSL tests four main areas each contest:
- LIFO / FIFO structures — stacks, queues, deques
- Prefix / Postfix / Infix notation — expression evaluation and conversion
- Recursive functions — trace execution, compute output
- Boolean algebra — simplify expressions, truth tables
- Computer number systems — base conversion, two's complement
All of these are covered in contests/acsl_solutions.py.
MIT © Vijith Velamuri