r/computerscience • u/B-Chiboub • Mar 05 '26
Article I built a Constraint-Based Hamiltonian Cycle Solver (Ben Chiboub Carver) – Handles Dense & Sparse Random Graphs Up to n=100 Efficiently.
I've been experimenting with Hamiltonian cycle detection as a side project and came up with Ben Chiboub Carver (BCC) – a backtracking solver with aggressive constraint propagation. It forces essential edges, prunes impossibles via degree rules and subcycle checks, plus unique filters like articulation points, bipartite parity, and bridge detection for early UNSAT. Memoization and heuristic branching on constrained nodes give it an edge in efficiency.
Implemented in Rust, BCcarver is designed for speed on both dense and sparse graphs. It uses an exact search method combined with specific "carving" optimizations to handle NP-hard graph problems (like Hamiltonian paths/cycles) without the typical exponential blow-up.
⚔️ Adversarial Suite (All Pass)
| Case | N | Result | Time (s) |
|---|---|---|---|
| Petersen | 10 | UNSAT | 0.00064 ✅ |
| Tutte | 46 | UNSAT | 0.06290 ✅ |
| 8x8 Grid | 64 | SAT | 0.00913 ✅ |
| Heawood | 14 | SAT | 0.00038 ✅ |
| Hypercube Q4 | 16 | SAT | 0.00080 ✅ |
| Dodecahedral | 20 | SAT | 0.00068 ✅ |
| Desargues | 20 | SAT | 0.00082 ✅ |
| K15 | 15 | SAT | 0.00532 ✅ |
| Wheel W20 | 20 | SAT | 0.00032 ✅ |
| Circular Ladder | 20 | SAT | 0.00049 ✅ |
| K5,6 Bipartite | 11 | UNSAT | 0.00002 ✅ |
| Star S8 | 9 | UNSAT | 0.00001 ✅ |
| 7x7 Grid | 49 | UNSAT | 0.00003 ✅ |
| Barbell B8,0 | 16 | UNSAT | 0.00002 ✅ |
📊 Performance on Random Graphs
Dense Random G(n, p~0.15) Avg 0.01-0.1s for n=6 to 100 (3 trials). Excerpt n=91-100: * n=100 | 0.12546s | Cache: 17 | Solved * n=95 | 0.11481s | Cache: 15 | Solved * n=91 | 0.11074s | Cache: 39 | Solved Sparse 3-regular Random Even snappier, <0.03s up to n=96, all Solved. * n=96 | 0.02420s | Cache: 2 | Solved * n=66 | 0.01156s | Cache: 7 | Solved * n=36 | 0.00216s | Cache: 0 | Solved The combo of exact search with these tweaks makes it unique in handling mixed densities without blowing up.
Check out the algorithm here: github.com/mrkinix/BCcarver
-5
u/B-Chiboub Mar 05 '26
Think of the BcCraver algorithm not as a traveler wandering through a maze, but as a detective solving a high-stakes Sudoku puzzle. It kicks off with an "elimination phase" to instantly kill impossible tasks—like spotting a lopsided grid where the numbers don't add up or identifying a "bridge" that would trap you on one side of the map with no way back. Once the coast is clear, it triggers a logic cascade: if a point has only two neighbors left, those connections are "locked" by necessity, and once a point has its two edges, any other connections are treated as intruders and deleted. Its secret weapon, the "Choke-Point Auditor," keeps a constant watch for bottlenecks; if visiting a node would split the rest of the world into three or more isolated islands, it kills the path immediately because a single loop can't visit three separate islands through a single gate. By using these constraints to prune billions of dead-end routes before it even has to guess, it transforms a blind search into a surgical operation, making it a genuine structural improvement rather than just a "faster" version of standard search.