Skip to content

Carlixgonzam/Crucible

Repository files navigation

Crucible

An interactive algorithm laboratory built on top of CLRS

Verify invariants. Trace complexity. Understand — not just watch.

Kotlin Compose Coroutines CLRS


What is Crucible?

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.


Modules

1 — Red-Black Trees Cap. 13

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

2 — Max Flow: Edmonds-Karp Cap. 26

Visualization of the Edmonds-Karp algorithm for maximum flow in transport networks, using BFS to find augmenting paths.

  • Residual graphGf rendered synchronously alongside the original capacity network G, updated after each augmentation
  • Min-Cut identification — once max flow is reached, the minimum cut is highlighted visually with the saturated edges

3 — Dynamic Programming: LCS & Edit Distance Cap. 15

Exploration of optimal substructure through memoization tables for Longest Common Subsequence and Levenshtein Distance.

  • Interactive matrixdp[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)

4 — Computational Geometry: Graham Scan Cap. 33

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

Stack

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.


Getting started

# 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 run

Requirements: JDK 17+, IntelliJ IDEA with Kotlin plugin.


Project structure

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

Design principles

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.


Performance notes

  • Graham Scan and the DP matrix are tested up to n = 100 points / string length without frame drops
  • RB-Tree supports up to n = 500 nodes 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.

About

An interactive algorithm laboratory built with Kotlin and Jetpack Compose. Implements and verifies core algorithms from CLRS (Cormen) including Red-Black Trees, Edmonds-Karp Max Flow, Dynamic Programming (LCS), and Graham Scan with live invariant checking and step-by-step visualization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages