An interactive algorithm laboratory built on top of CLRS
Verify invariants. Trace complexity. Understand — not just watch.
Crucible is an interactive desktop laboratory for studying and verifying advanced algorithms. Every module follows the pseudocode from Introduction to Algorithms (Cormen, Leiserson, Rivest, Stein) strictly — the goal is not to make algorithms look pretty, but to make their invariants, recurrences and complexity visible and provable in real time.
A crucible is a container where materials are tested under extreme conditions. Here, algorithms are what gets tested.
Complete implementation of self-balancing binary search trees following the five RB-Tree properties from CLRS.
- Rotation visualizer — left/right rotations and recoloring animated step by step, one operation at a time
- Live invariant checker — panel that validates after every insert/delete:
- Root is black
- No two consecutive red nodes
- Equal black-height on all paths to leaves
- All leaves (NIL) are black
Visualization of the Edmonds-Karp algorithm for maximum flow in transport networks, using BFS to find augmenting paths.
- Residual graph —
Gfrendered synchronously alongside the original capacity networkG, updated after each augmentation - Min-Cut identification — once max flow is reached, the minimum cut is highlighted visually with the saturated edges
Exploration of optimal substructure through memoization tables for Longest Common Subsequence and Levenshtein Distance.
- Interactive matrix —
dp[i][j]fills cell by cell with spatial dependency highlighting: the three cells each entry depends on are marked as the computation progresses - Path traceback — animation of the optimal path from
dp[n][m]back to the base case, labeling each step (match, insert, delete, substitute)
Convex hull computation using Graham's scan algorithm on an interactive 2D canvas.
- Visual stack — live representation of the candidate point stack; points are pushed and popped as right-turns are detected
- Angular sort — visualization of the radial sort step with respect to the pivot point before the scan begins
| Layer | Technology |
|---|---|
| Language | Kotlin 1.9 |
| UI | Jetpack Compose Desktop + Canvas API |
| Concurrency | Kotlin Coroutines (suspend functions for step-by-step execution) |
| Build | Gradle |
| Reference | CLRS 4th Edition |
The algorithm logic is implemented as suspend functions. Each meaningful step suspends execution and emits state, which the Compose layer observes and renders. Speed is controlled via a slider that sets the delay between steps — no threads, no callbacks.
# 1. Clone
git clone https://github.com/your-username/crucible.git
cd crucible
# 2. Open in IntelliJ IDEA (2023.1+ recommended)
# File → Open → select the project folder
# 3. Run
./gradlew runRequirements: JDK 17+, IntelliJ IDEA with Kotlin plugin.
crucible/
├── src/
│ └── main/
│ └── kotlin/
│ ├── Main.kt # Entry point, navigation
│ ├── structures/
│ │ └── RedBlackTree.kt # RB-Tree + rotations + fix-up
│ ├── graphs/
│ │ └── EdmondsKarp.kt # BFS-based max flow
│ ├── dp/
│ │ ├── LCS.kt # Longest Common Subsequence
│ │ └── EditDistance.kt # Levenshtein
│ ├── geometry/
│ │ └── GrahamScan.kt # Convex hull
│ └── ui/
│ ├── components/ # Shared Compose components
│ └── screens/ # One screen per module
├── build.gradle.kts
└── README.md
Invariants over animation. Most algorithm visualizers show you movement. Crucible shows you why the algorithm is correct. The invariant checker runs after every operation and fails visibly if a property is violated — useful for catching bugs in your own implementations.
Step granularity. Each suspend function yields at the smallest meaningful unit of work. For RB-Trees that means after each rotation. For Edmonds-Karp, after each BFS traversal. You can pause, rewind and inspect intermediate states.
No magic. The implementation follows the CLRS pseudocode line by line. Variable names match the textbook. If you have the book open, you can follow exactly where in the algorithm the visualization is at any given moment.
- Graham Scan and the DP matrix are tested up to
n = 100points / string length without frame drops - RB-Tree supports up to
n = 500nodes with smooth rotation animations - Edmonds-Karp tested on graphs with up to 50 nodes and 200 edges
Built on the shoulders of Cormen, Leiserson, Rivest and Stein.