Short answer: Dial’s algorithm is Dijkstra for nonnegative integer weights whose maximum is C. It keeps a bucket for each possible distance. Because an edge increases distance by at most C, a circular array of C+1 buckets holds the whole frontier. Scanning buckets in order and relaxing edges is O(V·C + E) in the form that walks empty buckets up to the largest finite distance. The heap has disappeared, and C has taken its place in the bound.
What the problem actually asks
A binary heap is a general priority queue. Integer distances need only a list of vertices sitting at each exact distance. The next vertex to settle is the smallest nonempty bucket. If weights lie in 0..C, once distance d is being settled the only new distances are in d..d+C, so buckets can wrap modulo C+1.
The cost moves from the logarithm of the heap to the number of buckets the scan walks. A large C makes that walk more expensive than a heap. A tiny C makes it cheaper.
What the algorithm guarantees
Correctness is Dijkstra’s correctness restricted to nonnegative integer weights. Each vertex is settled once, when its bucket is processed. Time is O(E + V·C) for the classic implementation whose outer scan advances a distance cursor up to the maximum finite distance, which is at most (V−1)·C. The circular form uses O(C) buckets plus the vertex records, rather than a bucket for every possible distance in advance. Extra memory beyond the graph is Θ(V+C).
When C = 1 the structure is 0-1 BFS and the bound is linear. When C is larger than a small constant and E is moderate, a binary heap’s O((V+E) log V) is the better engineering choice. Dial does not accept a non-integer weight, because there is no bucket for it.
The working steps
- Set dist[source] = 0. Place the source in bucket 0. The circular bucket array has length C+1.
- Advance a cursor from distance 0 upward until every vertex is settled or the remaining vertices are unreachable. The cursor may skip empty buckets.
- Settle each vertex in the bucket of the current distance, and do not resettle a vertex whose distance was already final.
- An edge of weight w updates the head’s distance and moves that vertex to the bucket (dist mod (C+1)).
- Stop when a full cycle of C+1 empty steps proves that no larger finite distance is waiting. Unreached vertices stay at infinity.
The bound trades the heap logarithm for a factor C. It is attractive for very small integer C and unattractive when C is in the thousands and a heap would have touched far fewer entries. It is still Dijkstra, so a negative weight is still illegal.
Approaches that look simpler and fail
| Approach | Why it fails when C is not part of the cost |
|---|---|
| Allocate a bucket per possible distance up to (V−1)·C with no circular reuse | The result can be correct and the memory is huge. The C+1 circular array is the form that matches the proof’s memory. |
| Use the algorithm for floating-point weights | Buckets are integer distances. A float has no finite set of residues modulo C+1. |
| Ignore empty-bucket scans in the complexity | The cursor may walk C steps per vertex in the worst case. That term is why a large C loses to a heap. |
| Apply it when weights exceed C and hope the modulo wraps correctly | A wrap collision puts two different distances in one bucket. The settle order is then wrong. |
Weights in {0, 1} belong to 0-1 BFS, which is this idea with a deque instead of a cursor. Arbitrary nonnegative weights belong to a binary-heap Dijkstra.
A working example
This Python fragment buckets integer distances in a circular array of width C+1. Edge weights are 0, 1, or 2. It prints the same distances a shortest-path computation would, 0 1 0 3.
from collections import deque
adj = {0: [(1, 1), (2, 0)], 1: [(3, 2)], 2: [(3, 3)], 3: []}
C = 3
n = 4
dist = [10**9] * n
dist[0] = 0
buckets = [deque() for _ in range(C + 1)]
buckets[0].append(0)
pending = 1
while pending:
for _ in range(C + 1):
while buckets[0]:
u = buckets[0].popleft()
pending -= 1
for v, w in adj[u]:
nd = dist[u] + w
if nd < dist[v]:
dist[v] = nd
buckets[w].append(v)
pending += 1
buckets = buckets[1:] + buckets[:1]
assert dist == [0, 1, 0, 3]
print(*dist)
Where it is used
Dial’s algorithm is the bucket queue for shortest paths whose edge weights are small integers, such as a grid of hop costs. 0-1 BFS is the two-bucket special case. Dijkstra’s binary heap is the algorithm once the weights are arbitrary nonnegative numbers.
When you can drop this algorithm
Drop Dial’s algorithm when C is not small. A binary heap is simpler and usually faster. Keep it for nonnegative integers bounded by a small C, where walking buckets beats heap traffic.
Why this stays published
We publish this so a search for Dial’s algorithm returns the circular C+1 buckets and the V·C term in the running time. Dial’s algorithm implements Dijkstra for integer weights up to C with C+1 distance buckets, in O(V·C + E) time.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
