arXiv:2608.26952cs.DSAug 2026

Manuscript Offprint

arXiv:2608.26952

On the Instance Optimality of Bidirectional Dijkstra's Algorithm

Matic Požar

Abstract

Recent work by Haeupler, Hladík, Rozhon, Tarjan, and Tětek on the instance optimality of shortest-path algorithms established several results concerning Dijkstra's algorithm and bidirectional Dijkstra's algorithm in weighted and unweighted graphs. Motivated by these results, we revisit the question of instance optimality for shortest st-path algorithms in the standard query model.

We identify several issues in the analysis of the instance optimality of both unidirectional and bidirectional Dijkstra's algorithms and provide corresponding counterexamples. We then propose a minimal simple modification of the bidirectional Dijkstra algorithm and prove that the resulting variant is instance optimal in the weighted setting. Furthermore, we revisit the unweighted case, provide a simplified proof of the lower bound showing that no algorithm can achieve instance optimality up to a factor better than O(Δ)O(\Delta), where Δ\Delta denotes the maximum degree of the graph, and discuss the implications of this result for approximation algorithms. Finally, we make progress on the open problem of instance optimality in simple graphs. We show that if the problem instance satisfies n≥m/16n \geq m/16, where n is the number of nodes and m is the number of edges queried by our algorithm, then it is optimal up to a constant factor. Additionally, we show instance optimality for a broad class of instances, in particular when the largest degree in the graph is at most the square root of the number of explored edges, our algorithm exhibits optimality up to a constant factor.

1 Introduction

The shortest st-path problem asks for a path of minimum length from a given node ss to a target node tt in a weighted graph GG. Negative edge weights introduce significant challenges when designing shortest-path algorithms, as they can invalidate greedy strategies. The Bellman–Ford algorithm [4, 14] solves the problem in the absence of negative cycles in O(∣V∣⋅∣E∣)O(|V| \cdot |E|) time. For graphs with non-negative edge weights, Dijkstra's algorithm [6] provides the canonical solution. It employs a greedy approach, using a priority queue to repeatedly select the node with the smallest distance computed so far. An implementation using Fibonacci heaps [8] achieves a time complexity of O(∣E∣+∣V∣log⁡∣V∣)O(|E| + |V| \log |V|). Moreover, it has been shown that among all algorithms based solely on comparisons and addition, Dijkstra's algorithm is asymptotically optimal [17, 16].

Algorithms are traditionally evaluated according to worst-case or average-case guarantees. A considerably stronger notion is that of instance optimality [1, 7]. An algorithm A is instance optimal with respect to a complexity measure T if, for any given input x, no other correct algorithm A′A' can, in expectation, solve x using fewer queries than A, up to a constant factor. Here we will focus on instance optimality in the context of shortest st-path problems, however, the literature in this domain is vast and includes results in sorting with partial information [12], finding the convex hull [3], and ordering vertices by distance from a source vertex [13, 20].

Any correct algorithm for computing the shortest st-path must satisfy two requirements. First, it must identify a shortest st-path. Second, it must be able to certify, with sufficiently high confidence, that the path returned is indeed optimal. While classical algorithms such as Dijkstra's algorithm and breadth-first search satisfy both requirements, they are largely agnostic to the particular structure of the input graph. Consequently, they do not exploit special topological features that may allow substantially faster solutions on specific instances. This observation suggests a possible obstacle to instance optimality: an algorithm tailored to a particular graph family may be able to identify a shortest path using significantly fewer queries, provided it can still certify that no shorter path exists.

The central theme of the first part of this paper is that the difficulty of the shortest st-path problem lies not only in finding a candidate path, but also in proving that the candidate is optimal. Our counterexamples exploit precisely this distinction. We construct algorithms that use inexpensive structural shortcuts to identify a shortest path and then employ lower bounds on the shortest-path length to certify optimality. In the case of unidirectional Dijkstra's algorithm, this leads to improvements by a factor of O(Δ)O(\Delta), where Δ\Delta denotes the maximum degree of the graph. On the other hand, we show that a slight modification of bidirectional Dijkstra's algorithm effectively performs the additional work necessary to establish such lower bounds, thereby preventing the existence of substantially faster shortcut-based algorithms.

Haeupler, Hladík, Rozhon, Tarjan, and Tětek [11] present several results concerning the instance optimality of Dijkstra's algorithm and its variants. In particular, they claim that, under certain conditions, Dijkstra's algorithm is instance optimal, that their implementation of bidirectional Dijkstra's algorithm achieves instance optimality, and that in the unweighted case bidirectional breadth-first search is instance optimal up to a factor of O(Δ)O(\Delta). We revisit these results and show that some of the arguments are incomplete and require refinement.

Our contributions are as follows. First, we present a family of counterexamples showing that the implementations of Dijkstra's algorithm and bidirectional Dijkstra's algorithm considered in [11] are not instance optimal. More precisely, we show that they can be outperformed by a factor of Θ(Δ)\Theta(\Delta) on certain graph families. Second, we identify the key issue in the proof of instance optimality for bidirectional Dijkstra's algorithm and propose a simple modification of the algorithm. We prove that the resulting variant is instance optimal in the weighted setting. This allows us to provide a simplified proof of instance optimality for the modified bidirectional Dijkstra's algorithm. Third, we revisit the unweighted setting and provide a simplified proof of the lower bound showing that no algorithm can achieve instance optimality up to a factor better than O(Δ)O(\Delta). Finally, we make considerable progress on the open problem concerning instance optimality of bidirectional Dijkstra's algorithm in simple graphs. First, we show that every correct algorithm that uses a sufficiently small number of queries must in turn query a constant fraction of all the nodes in the graph. Secondly, we show the full claim for graph instances whose maximum degree of explored nodes is at most the square root of the number of explored edges. Some particular implications of our results include instance optimality for classes of graphs where the average degree of the explored nodes is bounded by an explicit constant, and classes where the number of explored edges is Ω(n2)\Omega(n^2), where nn is the number of explored nodes. This covers the sparsest and densest of problem instances, making the general claim more plausible.

The paper is organized as follows. In Section 2, we introduce the fundamental concepts used throughout the paper. Section 3 studies a restricted setting that illustrates the main ideas behind our counterexamples. Section 4 considers the general weighted setting and establishes instance optimality of a modified bidirectional Dijkstra algorithm. Section 5 discusses the unweighted case and approximation-related observations. Section 6 addresses the more challenging setting of simple graphs and provides a partial resolution of the corresponding open problem. Finally, Section 7 concludes the paper.