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 (Cslib.Algorithms.WordRAM.Dijkstra.ListInstance) is a directed graph on Fin n
given by its adjacency lists of (target, weight) pairs, with natural-number weights, and a
source vertex. The lists may repeat a pair of endpoints (parallel edges) and may contain
self-loops. The instance determines a weight-matrix instance of
Cslib.Algorithms.WordRAM.Dijkstra.Instance that keeps, for each pair of endpoints, the
lightest of its edges (Cslib.Algorithms.WordRAM.Dijkstra.ListInstance.toInstance); the distance
is the distance of that instance.
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.
Main definitions #
Cslib.Algorithms.WordRAM.Dijkstra.ListInstance: a directed graph by adjacency lists, with a source.Cslib.Algorithms.WordRAM.Dijkstra.ListInstance.toInstance: its weight-matrix instance.Cslib.Algorithms.WordRAM.Dijkstra.ListInstance.encode: its input words.Cslib.Algorithms.WordRAM.Dijkstra.LogLinearSpec: a flat program computes every distance from the source withinK (m + 1) (⌊log₂ n⌋ + 1)instructions.Cslib.Algorithms.WordRAM.Dijkstra.LogLinearStatement: some program meetsLogLinearSpec.
Main results #
Cslib.Algorithms.WordRAM.Dijkstra.ListInstance.lightest_eq_some_iff: the matrix entry of a pair of endpoints is the least weight of the edges between them.Cslib.Algorithms.WordRAM.Dijkstra.ListInstance.lightest_eq_none_iff: it is absent exactly when there is no such edge.
References #
An instance of the single-source shortest-path problem given by adjacency lists: a
directed graph on Fin n and a source vertex. The list adj u holds a pair (v, c) for each
edge from u to v of weight c; it may hold several pairs with the same v.
- n : ℕ
The number of vertices.
The adjacency lists.
The source.
Instances For
The least weight of an edge from u to v, and none when there is no such edge.
Instances For
The weight-matrix instance with the same vertices and source, whose entry for u and v is
the least weight of an edge from u to v. Keeping a lightest edge between each pair preserves
distances.
Instances For
The shortest-path distance from u to v: the distance of the weight-matrix instance,
Cslib.Algorithms.WordRAM.Dijkstra.Instance.dist.
Instances For
The number of edges.
Instances For
The largest edge weight, and 0 when there is no edge.
Instances For
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).
Instances For
The matrix entry of u and v is c exactly when c is the least weight of an edge from
u to v.
Shortest paths in O((m + 1) log n) time. 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, halts within
K (m + 1) (⌊log₂ n⌋ + 1) 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.