Skip to content

Word ladder

Shortest word ladders, distance profiles, and connected components over Knuth's Stanford GraphBase five-letter words, solved over four representations of the same graph: an implicit adjacency that stores no edge, and the three stored layouts of `knotkit/graph`.

Shortest word ladders, distance profiles, and connected components over Knuth’s Stanford GraphBase five-letter words, solved over four representations of the same graph: an implicit adjacency that stores no edge, and the three stored layouts of knotkit/graph.

16 shortest ladders take 0.79 ms on compressed-sparse-row against 14.12 ms on the implicit graph; packed postings retain 96.8% less memory

  • knotkit/graph: Provides breadth-first search, Dijkstra, topological order, and connected components over integer-vertex graphs, stored as adjacency lists, compressed sparse rows, or an adjacency matrix
  • knotkit/inverted-index: Indexes records by exact keys and scans sorted record IDs for one key or the union of several, using packed posting lists
{"v":1,"box":[55.3681,94.1597,933.3333,437.3555],"x":{"s":"linear","lim":[-1.08,25.08],"inv":false,"g":0,"t":"Single-letter changes (chaos → order takes 12; 1,264 of 5,757 words are unreachable)","tk":[[0,"0"],[7,"7"],[11,"11"],[18,"18"],[24,"24"]]},"y":{"s":"linear","lim":[-4.47674159804,104.498998442],"inv":false,"g":0,"tk":[[0,"0"],[50,"50"],[100,"100"]]},"ti":"Same 4,493 words: half lie within 7 changes of chaos, 11 of order","a":[{"k":"line","c":"#fffff8","s":"x","d":[0,0.0222568439795,1,0.133541063877,2,0.556421099488,3,1.93634542622,4,6.34320053416,5,17.1600267082,6,34.5871355442,7,55.8869352326,8,76.6303138215,9,87.7142221233,10,93.3229468061,11,96.728243935,12,98.3529935455,13,99.1764967728,14,99.5548631204,15,99.8219452482,16,99.8887157801,17,99.977743156,18,100,19,100,20,100,21,100,22,100,23,100,24,100],"p":[91.61,423.19,125.18,422.84,158.74,421.5,192.3,417.16,225.86,403.28,259.42,369.22,292.98,314.33,326.54,247.25,360.11,181.93,393.67,147.02,427.23,129.36,460.79,118.63,494.35,113.52,527.91,110.92,561.47,109.73,595.03,108.89,628.6,108.68,662.16,108.4,695.72,108.33,729.28,108.33,762.84,108.33,796.4,108.33,829.96,108.33,863.53,108.33,897.09,108.33]},{"k":"line","c":"#1d5fa6","s":"x","d":[0,0.0222568439795,1,0.133541063877,2,0.556421099488,3,1.93634542622,4,6.34320053416,5,17.1600267082,6,34.5871355442,7,55.8869352326,8,76.6303138215,9,87.7142221233,10,93.3229468061,11,96.728243935,12,98.3529935455,13,99.1764967728,14,99.5548631204,15,99.8219452482,16,99.8887157801,17,99.977743156,18,100,19,100,20,100,21,100,22,100,23,100,24,100],"p":[91.61,423.19,125.18,422.84,158.74,421.5,192.3,417.16,225.86,403.28,259.42,369.22,292.98,314.33,326.54,247.25,360.11,181.93,393.67,147.02,427.23,129.36,460.79,118.63,494.35,113.52,527.91,110.92,561.47,109.73,595.03,108.89,628.6,108.68,662.16,108.4,695.72,108.33,729.28,108.33,762.84,108.33,796.4,108.33,829.96,108.33,863.53,108.33,897.09,108.33]},{"k":"line","c":"#fffff8","s":"x","d":[0,0.0222568439795,1,0.0667705319386,2,0.178054751836,3,0.311595815713,4,0.645448475406,5,1.60249276653,6,4.7852214556,7,11.974182061,8,23.8148230581,9,36.0783440908,10,48.3641219675,11,60.5386156243,12,72.3347429335,13,82.9957711996,14,91.3643445359,15,95.615401736,16,98.0191408858,17,99.1097262408,18,99.5103494325,19,99.7774315602,20,99.8664589361,21,99.9109726241,22,99.9332294681,23,99.977743156,24,100],"p":[91.61,423.19,125.18,423.05,158.74,422.7,192.3,422.28,225.86,421.22,259.42,418.21,292.98,408.19,326.54,385.55,360.11,348.26,393.67,309.64,427.23,270.94,460.79,232.6,494.35,195.45,527.91,161.88,561.47,135.52,595.03,122.14,628.6,114.57,662.16,111.13,695.72,109.87,729.28,109.03,762.84,108.75,796.4,108.61,829.96,108.54,863.53,108.4,897.09,108.33]},{"k":"line","c":"#c4501b","s":"x","d":[0,0.0222568439795,1,0.0667705319386,2,0.178054751836,3,0.311595815713,4,0.645448475406,5,1.60249276653,6,4.7852214556,7,11.974182061,8,23.8148230581,9,36.0783440908,10,48.3641219675,11,60.5386156243,12,72.3347429335,13,82.9957711996,14,91.3643445359,15,95.615401736,16,98.0191408858,17,99.1097262408,18,99.5103494325,19,99.7774315602,20,99.8664589361,21,99.9109726241,22,99.9332294681,23,99.977743156,24,100],"p":[91.61,423.19,125.18,423.05,158.74,422.7,192.3,422.28,225.86,421.22,259.42,418.21,292.98,408.19,326.54,385.55,360.11,348.26,393.67,309.64,427.23,270.94,460.79,232.6,494.35,195.45,527.91,161.88,561.47,135.52,595.03,122.14,628.6,114.57,662.16,111.13,695.72,109.87,729.28,109.03,762.84,108.75,796.4,108.61,829.96,108.54,863.53,108.4,897.09,108.33]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"line","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 0 7 11 18 24 Single-letter changes (chaos → order takes 12; 1,264 of 5,757 words are unreachable) 0 50 100 chaos: all within 18 order: all within 24 Share of the reachable words within this many changes (%) From chaos From order Same 4,493 words: half lie within 7 changes of chaos, 11 of order
{"v":1,"box":[55.3681,122.3921,485.3333,437.3555],"x":{"s":"linear","lim":[-1.08,25.08],"inv":false,"g":0,"t":"Single-letter changes (chaos → order takes 12; 1,264 of 5,757 words are unreachable)","tk":[[0,"0"],[7,"7"],[11,"11"],[18,"18"],[24,"24"]]},"y":{"s":"linear","lim":[-4.47674159804,104.498998442],"inv":false,"g":0,"tk":[[0,"0"],[50,"50"],[100,"100"]]},"ti":"Same 4,493 words: half lie within 7\nchanges of chaos, 11 of order","a":[{"k":"line","c":"#fffff8","s":"x","d":[0,0.0222568439795,1,0.133541063877,2,0.556421099488,3,1.93634542622,4,6.34320053416,5,17.1600267082,6,34.5871355442,7,55.8869352326,8,76.6303138215,9,87.7142221233,10,93.3229468061,11,96.728243935,12,98.3529935455,13,99.1764967728,14,99.5548631204,15,99.8219452482,16,99.8887157801,17,99.977743156,18,100,19,100,20,100,21,100,22,100,23,100,24,100],"p":[73.12,424.35,89.55,424.03,105.99,422.81,122.43,418.82,138.86,406.08,155.3,374.82,171.73,324.45,188.17,262.89,204.61,202.94,221.04,170.9,237.48,154.69,253.91,144.85,270.35,140.16,286.79,137.78,303.22,136.68,319.66,135.91,336.09,135.72,352.53,135.46,368.97,135.4,385.4,135.4,401.84,135.4,418.27,135.4,434.71,135.4,451.15,135.4,467.58,135.4]},{"k":"line","c":"#1d5fa6","s":"x","d":[0,0.0222568439795,1,0.133541063877,2,0.556421099488,3,1.93634542622,4,6.34320053416,5,17.1600267082,6,34.5871355442,7,55.8869352326,8,76.6303138215,9,87.7142221233,10,93.3229468061,11,96.728243935,12,98.3529935455,13,99.1764967728,14,99.5548631204,15,99.8219452482,16,99.8887157801,17,99.977743156,18,100,19,100,20,100,21,100,22,100,23,100,24,100],"p":[73.12,424.35,89.55,424.03,105.99,422.81,122.43,418.82,138.86,406.08,155.3,374.82,171.73,324.45,188.17,262.89,204.61,202.94,221.04,170.9,237.48,154.69,253.91,144.85,270.35,140.16,286.79,137.78,303.22,136.68,319.66,135.91,336.09,135.72,352.53,135.46,368.97,135.4,385.4,135.4,401.84,135.4,418.27,135.4,434.71,135.4,451.15,135.4,467.58,135.4]},{"k":"line","c":"#fffff8","s":"x","d":[0,0.0222568439795,1,0.0667705319386,2,0.178054751836,3,0.311595815713,4,0.645448475406,5,1.60249276653,6,4.7852214556,7,11.974182061,8,23.8148230581,9,36.0783440908,10,48.3641219675,11,60.5386156243,12,72.3347429335,13,82.9957711996,14,91.3643445359,15,95.615401736,16,98.0191408858,17,99.1097262408,18,99.5103494325,19,99.7774315602,20,99.8664589361,21,99.9109726241,22,99.9332294681,23,99.977743156,24,100],"p":[73.12,424.35,89.55,424.22,105.99,423.9,122.43,423.52,138.86,422.55,155.3,419.79,171.73,410.59,188.17,389.81,204.61,355.59,221.04,320.14,237.48,284.63,253.91,249.45,270.35,215.35,286.79,184.54,303.22,160.35,319.66,148.07,336.09,141.12,352.53,137.97,368.97,136.81,385.4,136.04,401.84,135.78,418.27,135.65,434.71,135.59,451.15,135.46,467.58,135.4]},{"k":"line","c":"#c4501b","s":"x","d":[0,0.0222568439795,1,0.0667705319386,2,0.178054751836,3,0.311595815713,4,0.645448475406,5,1.60249276653,6,4.7852214556,7,11.974182061,8,23.8148230581,9,36.0783440908,10,48.3641219675,11,60.5386156243,12,72.3347429335,13,82.9957711996,14,91.3643445359,15,95.615401736,16,98.0191408858,17,99.1097262408,18,99.5103494325,19,99.7774315602,20,99.8664589361,21,99.9109726241,22,99.9332294681,23,99.977743156,24,100],"p":[73.12,424.35,89.55,424.22,105.99,423.9,122.43,423.52,138.86,422.55,155.3,419.79,171.73,410.59,188.17,389.81,204.61,355.59,221.04,320.14,237.48,284.63,253.91,249.45,270.35,215.35,286.79,184.54,303.22,160.35,319.66,148.07,336.09,141.12,352.53,137.97,368.97,136.81,385.4,136.04,401.84,135.78,418.27,135.65,434.71,135.59,451.15,135.46,467.58,135.4]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"line","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"}],"lg":[]} 0 7 11 18 24 Single-letter changes (chaos → order takes 12; 1,264 of 5,757 words are unreachable) 0 50 100 chaos: all within 18 order: all within 24 Share of the reachable words within this many changes (%) From chaos From order Same 4,493 words: half lie within 7 changes of chaos, 11 of order
  • chaos to order: 12 single-letter changes.
  • chaos -> chaps -> chops -> coops -> corps -> cores -> codes -> coder -> cider -> eider -> elder -> older -> order
  • The Stanford GraphBase dictionary has 5757 words. From chaos, 1264 are unreachable.

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:word-ladder

problems/word-ladder/README.md states the fixture, the seed, and the result table.