Dijkstra's algorithm on the word RAM with adjacency lists: statements #
This file states, without proof, what a single-source shortest-path program on the word RAM
must satisfy to run in O((m + 1) log n) time on a graph with n vertices and m edges, the
bound of Dijkstra's algorithm with a binary heap Dijkstra
Cormen et al., Section 24.3. The bound has no n term: memory past the input starts
at 0, so the per-vertex arrays need no initialization, and the offsets give the adjacency list
of any vertex directly, so the program touches only the vertices it reaches.
An instance is an adjacency-list instance Cslib.Algorithms.Dijkstra.ListInstance, and its
distance is Cslib.Algorithms.Dijkstra.ListInstance.dist; both are machine-free. This file adds
the input words and the output convention. The program reads the input words n, the source,
the n + 1 offsets of the adjacency lists in the edge array, and the edges in order, each as two
words, its target and its weight. When it halts, the n memory cells just past the input hold
the distances from the source, with 0 for an unreachable vertex and d + 1 for distance d
(Cslib.Algorithms.WordRAM.Dijkstra.encodeDist).
Main definitions #
Cslib.Algorithms.Dijkstra.ListInstance.encode: the input words of an instance.Cslib.Algorithms.Dijkstra.ListInstance.outAddr: the output address of a vertex.Cslib.Algorithms.WordRAM.Dijkstra.encodeDist: a distance as a word.Cslib.Algorithms.WordRAM.Dijkstra.decodeDist: the distance a word encodes.Cslib.Algorithms.WordRAM.Dijkstra.ShortestPathSpec: a flat program computes every distance from the source within a per-instance step boundbound G.Cslib.Algorithms.WordRAM.Dijkstra.LogLinearSpec:ShortestPathSpecinstantiated withK (m + 1) (⌊log₂ n⌋ + 1)instructions.Cslib.Algorithms.WordRAM.Dijkstra.LogLinearStatement: some program meetsLogLinearSpec.
Main results #
Cslib.Algorithms.WordRAM.Dijkstra.decodeDist_encodeDist: decoding inverts the encoding of distances.Cslib.Algorithms.WordRAM.Dijkstra.ShortestPathSpec.mono: monotonicity in the step bound.
References #
The offset of the adjacency list of vertex u in the edge array: the number of edges out of
the vertices below u. The offset of n is the number m of edges.
The input words: n, the source, the offsets of the vertices 0, …, n, and then the edges of
the lists adj 0, …, adj (n - 1) in order, each as its target and its weight. Edge j in this
order has its target at word n + 3 + 2 j and its weight at word n + 4 + 2 j, and the edges
out of u are those with offset u ≤ j < offset (u + 1).
The output address of vertex v: the n cells just past the input, which has n + 2 m + 3
words and so ends at address n + 2 m + 3.
A distance as a word: 0 for an unreachable vertex and d + 1 for distance d.
The distance a word encodes: ⊤ for 0 and d for d + 1.
Decoding inverts the encoding of distances: a distance word decodes to its distance.
Single-source shortest-path program specification with step bound bound. At every word
size w that holds 8 (n + m + 2) (W + 2), where m is the number of edges and W the largest
weight, the flat program p, started on the input words of an adjacency-list instance G, halts
within bound G instructions, the final halt included, and its memory then holds at
G.outAddr v the encoded distance from the source to v, for every vertex v. The register
value returned by halt is not part of the result.
Relaxing the per-instance step bound preserves ShortestPathSpec.
Shortest paths in O((m + 1) log n) time. Instantiation of ShortestPathSpec with the
binary-heap Dijkstra step bound K (m + 1) (⌊log₂ n⌋ + 1).
Log-linear main theorem (statement). Some word-RAM program over the exact basis computes
all shortest-path distances from the source of a weighted directed graph with n vertices and
m edges, given by adjacency lists, within O((m + 1) log n) instructions.