Skip to content

Minimum cut

Global minimum cut for connected, undirected, unweighted multigraphs, implemented with classic Karger and recursive Karger–Stein over injected `knotkit/disjoint-set` layouts.

Global minimum cut for connected, undirected, unweighted multigraphs, implemented with classic Karger and recursive Karger–Stein over injected knotkit/disjoint-set layouts.

Classic contraction on a 75-vertex graph: indexed layout 0.0251 ms against 0.0393 ms for object

  • knotkit/disjoint-set: Tracks which elements belong to the same set, with dense-index, object, and struct-of-arrays layouts
  • knotkit/prng: Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests
{"v":1,"box":[83.3368,94.1597,913.7333,444.3555],"x":{"s":"log","lim":[3.21540396297,636.933966489],"inv":false,"g":0,"t":"Vertices (log scale)","tk":[[4,"4"],[8,"8"],[16,"16"],[32,"32"],[64,"64"],[128,"128"],[256,"256"],[512,"512"]],"b":10},"y":{"s":"log","lim":[7.23976657302,1497797.4622],"inv":false,"g":0,"tk":[[12,"12"],[100,"100"],[1000,"1,000"],[10000,"10K"],[100000,"100K"],[903642,"904K"]],"b":10},"ti":"Trials for 0.1% failure: 11,736× apart at 512","a":[{"k":"line","c":"#fffff8","s":"x","d":[4,38,8,190,16,826,32,3423,64,13923,128,56143,256,225466,512,903642],"p":[117.62,396.92,226.45,350.87,335.29,308.83,444.12,268.15,552.95,228.01,661.78,188.11,770.62,148.34,879.45,108.62]},{"k":"line","c":"#1d5fa6","s":"x","d":[4,38,8,190,16,826,32,3423,64,13923,128,56143,256,225466,512,903642],"p":[117.62,396.92,226.45,350.87,335.29,308.83,444.12,268.15,552.95,228.01,661.78,188.11,770.62,148.34,879.45,108.62]},{"k":"line","c":"#fffff8","s":"x","d":[4,12,8,21,16,30,32,39,64,49,128,58,256,68,512,77],"p":[117.62,429.9,226.45,413.89,335.29,403.68,444.12,396.18,552.95,389.64,661.78,384.82,770.62,380.27,879.45,376.71]},{"k":"line","c":"#c4501b","s":"x","d":[4,12,8,21,16,30,32,39,64,49,128,58,256,68,512,77],"p":[117.62,429.9,226.45,413.89,335.29,403.68,444.12,396.18,552.95,389.64,661.78,384.82,770.62,380.27,879.45,376.71]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 4 8 16 32 64 128 256 512 Vertices (log scale) 12 100 1,000 10K 100K 904K slope 2: grows as n² +9 to +10 per doubling: grows as log n Independent trials (upper bound) Karger Karger–Stein Trials for 0.1% failure: 11,736× apart at 512 {"v":1,"box":[83.3368,605.1597,913.7333,955.3555],"x":{"s":"log","lim":[22.7667458398,219.618562757],"inv":false,"g":1,"t":"Vertices in a vendored fixture (log scale), Apple M1 Pro, bun 1.4.4","tk":[[25,"25"],[50,"50"],[100,"100"],[200,"200"]],"b":10},"y":{"s":"log","lim":[0.00816446481758,1684.75992901],"inv":false,"g":1,"tk":[[0.01394506,"0.014 s"],[0.1,"0.1 s"],[1,"1 s"],[10,"10 s"],[100,"100 s"],[971.46409088,"971 s"]],"b":10},"ti":"Measured time to 0.1% failure: Karger 53–123× faster","a":[{"k":"line","c":"#fffff8","s":"x","d":[25,0.01394506,50,0.12756172,75,0.48125826,100,1.0622833,125,2.16376344,150,6.68937206,175,6.32164848,200,9.67038135],"p":[117.62,940.04,371.56,876.69,520.11,838.7,625.51,816.04,707.26,795.68,774.05,763.38,830.53,765,879.45,752.83]},{"k":"line","c":"#1d5fa6","s":"x","d":[25,0.01394506,50,0.12756172,75,0.48125826,100,1.0622833,125,2.16376344,150,6.68937206,175,6.32164848,200,9.67038135],"p":[117.62,940.04,371.56,876.69,520.11,838.7,625.51,816.04,707.26,795.68,774.05,763.38,830.53,765,879.45,752.83]},{"k":"line","c":"#fffff8","s":"x","d":[25,1.01043,50,9.79095015,75,32.83853688,100,97.2171497,125,245.10435586,150,354.6820098,175,777.63980196,200,971.46409088],"p":[117.62,817.47,371.56,752.48,520.11,717.85,625.51,686.79,707.26,660.32,774.05,649.75,830.53,627.28,879.45,620.92]},{"k":"line","c":"#c4501b","s":"x","d":[25,1.01043,50,9.79095015,75,32.83853688,100,97.2171497,125,245.10435586,150,354.6820098,175,777.63980196,200,971.46409088],"p":[117.62,817.47,371.56,752.48,520.11,717.85,625.51,686.79,707.26,660.32,774.05,649.75,830.53,627.28,879.45,620.92]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#1d5fa6"},{"k":"fill","c":"#c4501b"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 25 50 100 200 Vertices in a vendored fixture (log scale), Apple M1 Pro, bun 1.4.4 0.014 s 0.1 s 1 s 10 s 100 s 971 s Trials × measured median time per trial (s) Karger Karger–Stein Measured time to 0.1% failure: Karger 53–123× faster
{"v":1,"box":[83.3368,122.3921,465.7333,444.3555],"x":{"s":"log","lim":[3.21540396297,636.933966489],"inv":false,"g":0,"t":"Vertices (log scale)","tk":[[4,"4"],[8,"8"],[16,"16"],[32,"32"],[64,"64"],[128,"128"],[256,"256"],[512,"512"]],"b":10},"y":{"s":"log","lim":[7.23976657302,1497797.4622],"inv":false,"g":0,"tk":[[12,"12"],[100,"100"],[1000,"1,000"],[10000,"10K"],[100000,"100K"],[903642,"904K"]],"b":10},"ti":"Trials for 0.1% failure: 11,736× apart at\n512","a":[{"k":"line","c":"#fffff8","s":"x","d":[4,38,8,190,16,826,32,3423,64,13923,128,56143,256,225466,512,903642],"p":[99.12,400.74,149.24,358.41,199.36,319.75,249.48,282.36,299.59,245.45,349.71,208.77,399.83,172.2,449.95,135.68]},{"k":"line","c":"#1d5fa6","s":"x","d":[4,38,8,190,16,826,32,3423,64,13923,128,56143,256,225466,512,903642],"p":[99.12,400.74,149.24,358.41,199.36,319.75,249.48,282.36,299.59,245.45,349.71,208.77,399.83,172.2,449.95,135.68]},{"k":"line","c":"#fffff8","s":"x","d":[4,12,8,21,16,30,32,39,64,49,128,58,256,68,512,77],"p":[99.12,431.06,149.24,416.34,199.36,406.96,249.48,400.06,299.59,394.06,349.71,389.62,399.83,385.44,449.95,382.17]},{"k":"line","c":"#c4501b","s":"x","d":[4,12,8,21,16,30,32,39,64,49,128,58,256,68,512,77],"p":[99.12,431.06,149.24,416.34,199.36,406.96,249.48,400.06,299.59,394.06,349.71,389.62,399.83,385.44,449.95,382.17]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 4 8 16 32 64 128 256 512 Vertices (log scale) 12 100 1,000 10K 100K 904K slope 2: grows as n² +9 to +10 per doubling: grows as log n Independent trials (upper bound) Karger Karger–Stein Trials for 0.1% failure: 11,736× apart at 512 {"v":1,"box":[83.3368,633.3921,465.7333,955.3555],"x":{"s":"log","lim":[22.7667458398,219.618562757],"inv":false,"g":1,"t":"Vertices in a vendored fixture (log scale), Apple M1 Pro, bun 1.4.4","tk":[[25,"25"],[50,"50"],[100,"100"],[200,"200"]],"b":10},"y":{"s":"log","lim":[0.00816446481758,1684.75992901],"inv":false,"g":1,"tk":[[0.01394506,"0.014 s"],[0.1,"0.1 s"],[1,"1 s"],[10,"10 s"],[100,"100 s"],[971.46409088,"971 s"]],"b":10},"ti":"Measured time to 0.1% failure: Karger\n53–123× faster","a":[{"k":"line","c":"#fffff8","s":"x","d":[25,0.01394506,50,0.12756172,75,0.48125826,100,1.0622833,125,2.16376344,150,6.68937206,175,6.32164848,200,9.67038135],"p":[99.12,941.27,216.06,883.03,284.47,848.1,333.01,827.27,370.65,808.55,401.41,778.86,427.42,780.34,449.95,769.16]},{"k":"line","c":"#1d5fa6","s":"x","d":[25,0.01394506,50,0.12756172,75,0.48125826,100,1.0622833,125,2.16376344,150,6.68937206,175,6.32164848,200,9.67038135],"p":[99.12,941.27,216.06,883.03,284.47,848.1,333.01,827.27,370.65,808.55,401.41,778.86,427.42,780.34,449.95,769.16]},{"k":"line","c":"#fffff8","s":"x","d":[25,1.01043,50,9.79095015,75,32.83853688,100,97.2171497,125,245.10435586,150,354.6820098,175,777.63980196,200,971.46409088],"p":[99.12,828.59,216.06,768.83,284.47,736.99,333.01,708.44,370.65,684.11,401.41,674.39,427.42,653.73,449.95,647.88]},{"k":"line","c":"#c4501b","s":"x","d":[25,1.01043,50,9.79095015,75,32.83853688,100,97.2171497,125,245.10435586,150,354.6820098,175,777.63980196,200,971.46409088],"p":[99.12,828.59,216.06,768.83,284.47,736.99,333.01,708.44,370.65,684.11,401.41,674.39,427.42,653.73,449.95,647.88]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#1d5fa6"},{"k":"fill","c":"#c4501b"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 25 50 100 200 Vertices in a vendored fixture (log scale), Apple M1 Pro, bun 1.4.4 0.014 s 0.1 s 1 s 10 s 100 s 971 s Trials × measured median time per trial (s) Karger Karger–Stein Measured time to 0.1% failure: Karger 53–123× faster
  • The four-cycle has a cut of 2 edges (Karger–Stein with seed 42).
  • At 512 vertices the documented bounds give 903642 classic trials
  • and 77 Karger–Stein runs for at most 0.1% failure.
  • Measured on Apple M1 Pro, one classic trial grows as n^1.2 and one recursive run as n^3.1
  • over 25 to 200 vertices, so reaching 0.1% failure takes 53–123× longer with Karger–Stein.

Hover or focus a chart for exact values. Drawn by demo.ts at build time, from the fixtures the benchmark uses; it reproduces the README figure.

Terminal window
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:min-cut

problems/min-cut/README.md states the fixture, the seed, and the result table.