End-to-end Word-RAM topological sort and Kosaraju SCC programs #
Main definitions #
Cslib.Algorithms.WordRAM.DFS.sccIndexCode: combined forward DFS, transpose, and Kosaraju peeling pass (220 * N + 92 * Mc + 42instructions).Cslib.Algorithms.WordRAM.DFS.Graph,Cslib.Algorithms.WordRAM.DFS.Graph.m,Cslib.Algorithms.WordRAM.DFS.Graph.encodeCSR,Cslib.Algorithms.WordRAM.DFS.Graph.wordBound.Cslib.Algorithms.WordRAM.DFS.topoWords,Cslib.Algorithms.WordRAM.DFS.sccWords.Cslib.Algorithms.WordRAM.DFS.topoCode,Cslib.Algorithms.WordRAM.DFS.topoProgram.Cslib.Algorithms.WordRAM.DFS.sccCode,Cslib.Algorithms.WordRAM.DFS.sccProgram.
Main results #
Cslib.Algorithms.WordRAM.DFS.sccIndexCode_spec.Cslib.Algorithms.WordRAM.DFS.Graph.csrAt_init,Cslib.Algorithms.WordRAM.DFS.Graph.inputFits_encodeCSR.Cslib.Algorithms.WordRAM.DFS.topoCode_spec,Cslib.Algorithms.WordRAM.DFS.computesListInTime_topoProgram.Cslib.Algorithms.WordRAM.DFS.sccCode_spec,Cslib.Algorithms.WordRAM.DFS.computesListInTime_sccProgram.Cslib.Algorithms.WordRAM.DFS.not_readsWidth_sccIndexCode,Cslib.Algorithms.WordRAM.DFS.not_readsWidth_topoProgram,Cslib.Algorithms.WordRAM.DFS.not_readsWidth_sccProgram.
Forward DFS, transpose and Kosaraju peeling as one pass (O(N + M)) #
Kosaraju's strongly connected components on the CSR graph at kOffAddr wb: forward DFS
finishing order, CSR transpose, and peeling the transpose in reverse finishing order, writing the
topological component index of every vertex to kCompAddr wb N Mc.
sccIndexCode does not read the word width.
sccIndexCode is rand-free.
Kosaraju's algorithm on the word RAM in O(N + M) instructions. From the scratch layout
based at wb (with a CSR graph adj of at most Mc arcs at kOffAddr wb), sccIndexCode
writes indexComponents (sccs adj (List.finRange N)) u to kCompAddr wb N Mc + u for every
vertex u, leaving memory below wb unchanged.
Graphs in CSR form #
Linear word-size envelope 16 * (n + m + 1) covering the input and the scratch layout.
Every word of G.encodeCSR, and its length, fits any word width admitting
G.wordBound.
End-to-end programs #
Structured topological sort: setup, forward DFS, and reversed copy of the finishing order.
Structured strongly-connected-component indexing: setup, then sccIndexCode.
Flat topological-sort program returning topoWords G via ExecutesList.
Flat strongly-connected-component program returning sccWords G via ExecutesList.
Linear-time topological sort on the word RAM. From the CSR input G.encodeCSR, topoCode
leaves topoWords G (the reverse DFS finishing order, which by
Cslib.Algorithms.Lean.DFS.isTopologicalOrder_topologicalSort_iff is a topological order exactly
when G is acyclic) at the address in outReg, within 128 * (G.n + G.m + 1) - 1 instructions at
every word width w with Fits w G.wordBound.
Linear-time Kosaraju strongly connected components on the word RAM. From the CSR input
G.encodeCSR, sccCode leaves sccWords G (each vertex's topological component index in
Cslib.Algorithms.Lean.DFS.sccs; by
Cslib.Algorithms.Lean.DFS.IsSCCCondensation.indexComponents_eq_iff two vertices receive the same
index exactly when they are strongly connected) at the address in outReg, within
256 * (G.n + G.m + 1) - 1 instructions at every word width w with Fits w G.wordBound.
topoProgram computes topoWords in O(n + m) instructions
(Program.ComputesListInTime).
sccProgram computes sccWords in O(n + m) instructions
(Program.ComputesListInTime).
topoProgram does not read the word width.
topoProgram is rand-free.
sccProgram does not read the word width.
sccProgram is rand-free.