Documentation

CslibFrontier.Algorithms.WordRAM.DFS

Linear-time depth-first search on the word RAM #

Iterative depth-first search with an explicit stack on the standard-basis word RAM (Cslib.WordRAM.Basis.standard), after Tarjan and Cormen et al., Sections 22.3–22.5: DFS finishing order, topological sort, CSR transposition and Kosaraju's strongly connected components, each in O(N + M) instructions on a graph with N vertices and M arcs, proved equal to the pure functions of CslibFrontier.Algorithms.Lean.DFS.

Representation #

A graph adj : Fin N → List (Fin N) is held in compressed sparse row form (CSRAt): an offset array csrOffset adj 0, …, csrOffset adj N followed by the successor lists in order. All passes work in one scratch layout based at an address wb (kOffAddr, …, kTopAddr), with Mc words reserved for each arc array. The DFS stack holds 3 words per frame (vertex, next arc, arc end), so no recursion is needed. The engine (forwardDFSCode, transposeCSRCode, kosarajuIndexCode, sccIndexCode and their CSR primitives) is shared with CslibFrontier.Algorithms.WordRAM.TwoSAT.

The end-to-end programs read a Graph in the CSR input encoding Graph.encodeCSR ([n, m, off 0, …, off n] ++ arcs), so the input already is the forward CSR graph of the layout based at wb = 3, and return a list through Cslib.WordRAM.ExecutesList.

Main definitions #

Main results #

References #