Manuscript Offprint
arXiv:2608.24380Instance-Optimality of Bidirectional Dijkstra on Simple Graphs
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
We study the shortest-path problem on graphs with positive real-valued edge weights. Given a source vertex s and a target vertex t, the goal is to calculate the length of the shortest path from s to t. We are particularly interested in instances that can be solved in sublinear time.
Recently, Haeupler, Hladík, Rozhoň, Tarjan, and Tětek [HHR 25] proved that (a version of) the bidirectional Dijkstra's algorithm is instance-optimal on positively weighted multigraphs, both directed and undirected, considering the number of vertices and edges queried by the algorithm. Here, being instance-optimal means best within a constant factor on every possible instance, but this is only compared against algorithms that are correct on every valid instance.
However, multigraphs are not the canonical setting for the shortest-path problem. The problem is typically formulated on simple graphs without loops and parallel edges. therefore left as an open problem whether bidirectional Dijkstra remains instance-optimal on simple weighted graphs.
We answer this question, but for simple graphs, the answer is more complex, depending on the setting. We show that bidirectional Dijkstra is still instance-optimal on simple undirected weighted graphs under the order-oblivious model, where incident edges are given in a random order. In contrast, under the order-dependent model, where incident edges have a given order, we show that bidirectional Dijkstra is not instance-optimal: it is off by a factor of , where and denote the number of edges and vertices, respectively. Nonetheless, we show that this is the best possible in the sense that no algorithm can have an instance-optimality ratio of .
For simple directed weighted graphs, we show that bidirectional Dijkstra is not instance-optimal under either the order-oblivious or the order-dependent model, being off by a factor of in both cases. We further show that no algorithm can have instance-optimality ratio under the order-dependent model, or under the order-oblivious model when . On the positive side, the above results imply that bidirectional Dijkstra is instance-optimal up to logarithmic factors on all sparse directed and undirected graphs satisfying .
Besides the above main bounds, we also study the instance-optimality if we have an upper bound on the maximal degree of the graph, and for instances that can be solved in time.
Finally we show that most of the instance-non-optimality is due to degree-queries: if there are no degree-queries then bidirectional Dijkstra is order-dependent instance-optimal on undirected graphs and order-oblivious instance-optimal on directed graphs.
This work was supported by the VILLUM Foundation grant 54451.
Contents
1 Introduction 3
1.1 Model 6
1.2 Additional results 8
1.3 Paper Organization 10
2 Revisiting the Bidirectional Dijkstra's Algorithm 10
2.1 Dijkstra's Algorithm 10
2.2 Bidirectional Dijkstra 11
2.3 Fixed Minor Error From [HHR 25] 12
2.4 Correctness of Bidirectional Dijkstra 13
2.5 Properties of Bidirectional Dijkstra 14
3 Setting Up the Analysis Framework 15
3.1 Lower Bounds 16
3.2 Upper Bounds 16
4 Order-Oblivious Instance-Optimality for Undirected Graphs 18
5 Order-Dependent Instance-Non-Optimality for Directed Graphs 19
6 Order-Oblivious Instance-Non-Optimality for Directed Graphs 20
7 Order-Dependent Instance-Non-Optimality for Undirected Graphs 23
8 More Instance-Optimality 25
8.1 Directed Graphs 25
8.2 Undirected Graphs 28
8.3 Few high-degree vertices 30
9 No degree queries 31
9.1 Order-Oblivious Instance-Optimality for Directed Graphs 31
9.2 Order-Dependent Instance-Non-Optimality for Directed Graphs 32
9.3 Order-Dependent Instance-Optimality for Undirected Graphs 33
10 Zero-Weight Graphs and Unit-Weight Graphs 34
However, when going beyond worst-case analysis and considering graph instances that can be solved in time, a number of algorithms have been observed to significantly outperform Dijkstra's algorithm. One canonical example is bidirectional search [Dan63, Nic66], which simultaneously runs Dijkstra's algorithm forward from s and backward from t, terminating when the two searches meet. Although bidirectional Dijkstra still requires time in the worst case, it is often highly efficient in practice, exploring only a small portion of the graph before terminating.
Instance-optimality for positively weighted multigraphs. A recent work by Haeupler, Hladík, Rozhoň, Tarjan, and Tětek [HHR 25] provided a theoretical explanation for the superiority of bidirectional Dijkstra. They showed that, when alternating edge relaxations in the forward and backward searches, this simple algorithm is, surprisingly, instance-optimal on all weighted multigraphs with real positive weights. We are going to study what happens for the more standard case of simple graphs, but first we contextualize the result on multigraphs from [HHR 25].
Here, an instance-optimal algorithm [FLN03, Rou19] is the dream of an algorithm that is (close to) best on every single input instance. This covers not just worst-case or average-case instances, but also “easy” instances that can be solved in constant time. This contrasts algorithms with optimal worst-case or average-case guarantees that may spend worst-case or average-case time also on such easy instances. Notably, when discussing instance-optimality, we compete only against algorithms that are correct on every valid input instance. Such algorithms may be instance-smart, in the sense that they are tuned for a particular instance and may even know the correct answer for that instance in advance. However, since the actual input may differ, an instance-smart algorithm must still verify that its answer is correct on the given input. Note that instance-smart algorithms subsume algorithms that receive good but not fully trusted advice (e.g., advice from AI [MV22]), which likewise must verify their answers on the actual input instance.
We say that an algorithm A is instance-optimal within a factor , or that A is -instance-optimal, if for every input instance I, A is at most a factor slower than any correct (instance-smart) algorithm on I. The smallest such is called the instance-optimality ratio of A. When we say an algorithm is instance optimal, we typically mean that is constant. Such instance-optimality is often considered the ultimate notion of optimality [CL16, ABC17]. Finding an algorithm, especially a simple one, that is instance-optimal is therefore extremely appealing.
Unfortunately, instance-optimal algorithms exist only in rare situations [ABC17, HHR 24]. Some positive examples are known, e.g., in quantity estimation [DKLR00], database aggregation [FLN03], sequential estimation [VV16, DLSV23, NRTT24], computational geometry [ABC17, dBvR 25], distribution testing and learning [VV17, VV20, BCW25], PageRank estimation [TW25], and contextual bandits [LRN 22]. As mentioned above, [HHR 25] adds bidirectional Dijkstra to this exclusive list, showing that it is instance-optimal on all multigraphs, directed and undirected, with real positive weights. The instance-optimality ratio is constant when we measure query complexity (number of vertices and edges queried), and at most if we measure the actual running time.
For the above instance-optimality, it is critical that we only allow positive weights, that is, no zero weights. Bidirectional Dijkstra works correctly for the more general case of non-negative weights, but it is no longer instance-optimal. As proved in , for the shortest path problem with non-negative weights, there is no algorithm with instance-optimality ratio . The basic issue is that an instance-smart algorithm may know a “secret” path of length 0 from s to t. Since no shorter path can exist, it just has to verify this path. In fact, the bad instances are just instances of reachability where all edge weights are zero, which is hence one of the many problems that do not admit an instance-optimal algorithm.
Simple graphs versus multigraphs. The instance-optimality from is established only for positively weighted multigraphs, allowing both self-loops and parallel edges. Allowing parallel weighted edges may seem redundant for shortest-path computation, but recall that the main obstacle to obtaining instance-optimal algorithms is the existence of instance-smart algorithms tailored to perform exceptionally well on an individual instance. So to investigate the instance-optimality of Dijkstra's algorithm, which relaxes every incident edge when it visits a vertex, one would like to force any correct algorithm to do more or less the same. Parallel edges achieve exactly this: without them, the one-hop distance from u to v is known as soon as a single edge is found and its weight read, whereas with parallel edges one must scan the entire out-adjacency list of u (or the in-adjacency list of v) to be sure no lighter edge is hidden, which is always possible since edge weights are positive reals.
However, normally, the shortest-path problem is studied on simple graphs. Multigraphs reduce to this case simply by removing all loops and merging parallel edges into a single edge with the smallest weight available. It is therefore natural to ask what happens on simple graphs. This question was left open by , whose concluding remarks (where Theorem 1.1 denotes their instance-optimality result for positively weighted multigraphs) state:
“Our proof of Theorem 1.1 works for multigraphs that allow parallel edges and self-loops. While we believe that the possibility of self-loops can be avoided, we are not sure whether the same holds for parallel edges: We believe that whether Theorem 1.1 holds in the setting of simple graphs is an interesting open question.” [HHR 25]
Our contribution. We answer the above question, but the answer is more complex for positively weighted simple graphs, depending on the setting (the result from was that bidirectional Dijkstra is instance-optimal for positively weighted multigraphs in all the settings mentioned below). We show that bidirectional Dijkstra is still instance-optimal on simple undirected weighted graphs under the order-oblivious model, where incident edges are given in a random order. In contrast, under the order-dependent model, where incident edges have a given order, we show that bidirectional Dijkstra is not instance-optimal: it is off by a factor of . Nonetheless, we show that this is best possible, in the sense that every algorithm has instance-optimality ratio
For simple directed weighted graphs, we show that bidirectional Dijkstra is not instance-optimal under either the order-oblivious or the order-dependent model, being off by a factor of in both cases. We further show that every algorithm has an instance-optimality ratio under the order-dependent model, and under the order-oblivious model when . On the positive side, the above results imply that bidirectional Dijkstra is instance-optimal up to logarithmic factors on all sparse directed and undirected graphs satisfying .
Besides the above main bounds, we also study the instance optimality ratio if we have an upper bound on the maximal degree, and for instances that can be solved in time. A summary of
| Graph with degree query | Order model | Instance-optimality ratio of bidirectional Dijkstra | Instance-optimality ratio of every good algorithm |
|---|---|---|---|
| Undirected | oblivious | [Thm 4.1] (instance-optimal) | (trivial) |
| dependent | [Thm 8.8] [Thm 8.9] | [Thm 7.1] [Thm 7.2] | |
| Directed | oblivious | [Thm 6.2] [Thm 6.3] | [Thm 6.1] |
| dependent | [Thm 8.1] [Thm 8.2] | [Thm 5.1] [Thm 5.2] |
Table 1: Instance-optimality ratios for shortest path on simple weighted graphs with positive real weights. Note that any upper bound on the instance-optimality ratio established under the order-dependent model extends to the order-oblivious model. We thus have tight bounds on bidirectional Dijkstra in almost every setting. Here, and denote the numbers of vertices and edges in , respectively, and denotes the maximum in- and out-degree of . Additionally, denotes the instance-wise complexity, i.e., the minimum of the expected number of queries made by all good algorithms on instance . Thus, the condition means that the instance-optimality result holds for all instances whose instance-wise complexity satisfies . is an upper bound of the number of vertices with degree at least .
| Graph w/o degree query | Order model | Instance-optimality ratio of bidirectional Dijkstra | Instance-optimality ratio of every good algorithm |
|---|---|---|---|
| Undirected | oblivious | [Thm 9.3] (instance-optimal) | (trivial) |
| dependent | [Thm 9.3] (instance-optimal) | (trivial) | |
| Directed | oblivious | [Thm 9.1] (instance-optimal) | (trivial) |
| dependent | [Thm 8.2] | [Thm 9.2] |
Table 2: Instance-optimality ratios without degree queries for shortest path on simple weighted graphs with positive real weights. All symbols have the same explanations as in Table 1.
our results is given in Table 1. We will present these results in Section 1.2 after we have given a more detailed description of the model in Section 1.1.
Finally we show that most of the instance-non-optimality is due to degree-queries: bidirectional Dijkstra's algorithm does not use degree-queries, and if degree-queries are not supported, then bidirectional Dijkstra is instance-optimal on both directed and undirected positively weighted graphs in the order-oblivious model. The only exception to instance-optimality is for directed graphs in the order-dependent model. The results without degree queries are given in Table 2.
Relation to A* heuristic search and advice from AI. As discussed in [HHR+25], the popular A* search algorithm [HNR68] is a heuristic variant of Dijkstra's algorithm that is sometimes observed to run faster than bidirectional Dijkstra in practice. The A* algorithm relies on a heuristic estimate of the distance from each vertex v to the destination t, and runs Dijkstra's algorithm on the adjusted edge weights , where denotes the original weight of edge . If is exact and for all v, then all edges on these shortest paths have adjusted weight 0, and A* will only explore vertices on shortest paths from s to t.
Since Dijkstra does not work with negative edge-weights and A* builds on Dijkstra, the correctness of the A* heuristic search requires that the adjusted edge weight is non-negative for every edge ; otherwise A* may return an incorrect shortest s-t path. The heuristic estimate is therefore defined to be consistent only if all adjusted weights are non-negative, that is, if holds for every edge in the graph. Verifying consistency of requires checking the adjusted weights of all edges and therefore takes time. This nearly matches the worst-case running time of Dijkstra, so in practice, with A*, we just have to trust that is consistent. With this trust in , the A* search may outperform bidirectional Dijkstra, but this does not contradict instance-optimality of bidirectional Dijkstra since guaranteed correctness assumes the extra information that is consistent with respect to the given input graph. This point with a trusted was already discussed in [HHR+25].
Suppose now that we run A* with a that we do not fully trust to be consistent on the given input graph, e.g., could be an “advice” on the input provided by an AI system that we do not fully trust [MV22]. To be sure of correctness, we must verify that the path found is indeed a shortest path in the input graph, just as any other instance-smart algorithm must. Consequently, we cannot be significantly faster than an instance-optimal bidirectional Dijkstra that constructs the shortest path from scratch. Here, by an instance-optimal bidirectional Dijkstra we mean one of the cases where bidirectional Dijkstra is instance-optimal, e.g., positively weighted multi-graphs as proved in [HHR 25], or undirected simple graphs in the order-oblivious model as proved in this paper.
1.1 Model
Good algorithms. Recall that when we discussed instance-optimality, we had a set I of valid instances, and we compared only with correct algorithms, namely algorithms that return a correct answer on every . However, we can also compare with Monte Carlo randomized algorithms whose correctness is probabilistic. Accordingly, we say that a randomized algorithm A is good if on every valid instance it returns a correct answer with probability at least 9/10. The choice of the constant 9/10 is arbitrary, since standard probability amplification can boost any constant success probability greater than 1/2 to 9/10.
Instance-wise complexity and instance-optimality ratio. Recall that we have introduced the instance-optimality ratio of an algorithm as the smallest factor by which is slower than any correct algorithm on every valid input instance . We now define this notion more formally.
Let denote the expected number of queries made by an algorithm on an instance . The instance complexity of is then defined as the minimum for any good algorithm on the instance . Note that for the instance complexity of , we do not care how much time spends on other instances, so could be instance-smart, specially tuned for . However, to be good, has to verify the answer on so that it does not provide a wrong answer because it gets a different input . In particular, we note that cannot decrease if we increase the set of valid instances that algorithms have to be good on.
The instance-optimality ratio of A is defined as
that is, the smallest value of such that for every valid instance . We call instance-optimal if its instance-optimality ratio is a constant. When is not constant, we may want to parameterize it by an instance-parameter such as the size , e.g.,
Finally, it may be relevant to study the instance-optimality ratio of A on a subset C of valid instances as
We call A instance-optimal on C if is a constant.
An example from is that if the valid instances are multigraphs with positive integer weights, then the instance-optimality ratio of bidirectional Dijkstra is where bounds the maximal degree. However, if the valid instances include weight zero, then the instance-optimality ratio is constant on instances with only positive weights. Another example from is that a certain PageRank algorithm is instance-optimal except on digraphs with many vertices of very high degree. The latter example illustrates that even if an algorithm is not instance optimal on all the valid input instances (all digraphs), we can still hope that is instance-optimal on a rich and interesting subclass.
Query model for sublinear graph algorithms. We are particularly interested in instances on which the shortest-path problem can be solved in time. Like in , we therefore work in the standard adjacency-list query model for sublinear graph algorithms.
We assume that the input is a simple graph, with no self-loops or parallel edges; the graph has vertices, and all edges have positive real-valued weights. Additionally, we assume the number of vertices of the graph is sufficiently large and is known in advance. The graph is stored in incidence-list format. The vertices are numbered 1 to , and each is identified by its index; an algorithm has query access to all of them. Each vertex keeps a list of its outgoing edges and a list of its incoming edges. Given a vertex , the model supports degree queries INDEG() and OUTDEG(), which return the in- and out-degree of , and neighbor queries IN() and OUT(), which return the -th in- and out-neighbor of together with the weight of the corresponding edge (if exceeds the length of the relevant list, the query returns null). Each query has unit cost. We measure the complexity of an algorithm by its query complexity, i.e., the total number of queries it performs.
Throughout the paper we consider both directed and undirected graphs, but we state our model and algorithms only for the directed case: they naturally transfer to undirected graphs, since an undirected graph is simply a directed graph in which each vertex has the same in- and out-degree and the same in- and out-adjacency lists.
Order-dependent and order-oblivious. The shortest path problem normally refers to a graph with a set of vertices and a set of edges. However, when we store the graph for the above query model, we have to order vertices, indexing them . Moreover, for each vertex , we have to order the incident edges so that we can index the neighbors as and ,
When we discuss instance-optimality, it is important whether the orderings are considered part of the input or whether they are just random and provide no information beyond the graph itself. The former case is called order-dependent while the latter is order-oblivious.
For an instance-smart algorithm, it is better to be order-dependent, since it offers more information on the instance that it is tuned for. For example, the instance-smart algorithm may know the edge indices on the shortest path from s to t. All it has to do is to verify this path, and verify that there is no shorter path. In the case of zero-weight edges, it only has to verify the zero-length path, without having to verify that no shorter path exists in the graph.
From the perspective of the algorithm that hopes to be instance-optimal, the situation is the opposite. Even if the order is part of the instance, we still need to be best for all possible orderings, so we can think of the order as adversarially chosen. Internally, using randomization, it can always simulate a random order, and for bidirectional Dijkstra, it makes no asymptotic difference whether the order is random or adversarial, so we will always think of the order as adversarial.
Since the order is not a natural part of the graph instance, it may be fairer to say that, as in the order-oblivious setting, the order is not known to the instance-smart algorithm. When it starts, it only knows the indices of s and t, say, 1 and n. For example, in applications where vertices do not have comparable identifiers (e.g., webpages on the Internet, which are identified only by URLs), an adjacency list is more naturally viewed as an unordered set, and a neighbor query is usually implemented by returning a previously unseen neighbor chosen uniformly at random. Note that in the order-oblivious model, even though we think of the ordering as random, we still require a good algorithm to be correct with probability at least 9/10 for any possible ordering of any input instance.
We also emphasize that the order-oblivious model applies to the ordering of the vertex list. In particular, vertex indices cannot be considered part of the input, and accessing an unseen vertex by its index in the order-oblivious model should be viewed as sampling a vertex uniformly at random from the graph."
It follows that any upper bound on the instance-optimality ratio established under the order-dependent model also holds under the order-oblivious model. Dually, any lower bound established under the order-oblivious model extends to the order-dependent model.
1.2 Additional results
Recall that proved that bidirectional Dijkstra is instance-optimal for positively weighted multigraphs, both directed and undirected, in the order-dependent model, and hence also in the order-oblivious model. They left open the more typical case of simple graphs.
As discussed, we answer this question by showing that it remains instance-optimal for undirected graphs in the order-oblivious model, but not in any of the other models. In terms of and , the instance-optimality ratio is for undirected graphs in the order-dependent model and for directed graphs in both the order-dependent and order-oblivious models. These results imply that bidirectional Dijkstra is instance-optimal for .
In the following, we present several additional results that further characterize the instance-optimality ratio. All the results are summarized in Table 1, and all of them are understood to be for positively weighted simple graphs, directed or undirected.
Max-degree. If we have a bound on the maximal degree, then for directed graphs, we show that the instance-optimality ratio of bidirectional Dijkstra is in both the order-dependent and order-oblivious models. For undirected graphs, the bound in the order-dependent model is the cube root of this quantity, that is, . In all cases, bidirectional Dijkstra is instance-optimal.
when . More generally, we show that in the order-dependent model, the instance-optimality ratio of bidirectional Dijkstra is on directed graphs with at most vertices whose in-degree or out-degree is larger than .
Instance-optimality on easy instances. Recall that our whole motivation for considering bidirectional Dijkstra is that it sometimes only has to consider a small fraction of the graph. We are therefore particularly interested in “easy” cases with instance-complexity , that is, where some instance-smart algorithm can verify the shortest path in time. We claim that this setting is also very beneficial for bidirectional Dijkstra.
First, considering the opposite case where the instance-complexity is , then the instance-optimality ratio of is obtained by any algorithm with worst-case complexity . Our instance-optimality ratio upper-bound of is thus only interesting when the instance-complexity is . However, for the lower-bound, with instance-complexity , an instance-smart algorithm can record the degree of all vertices, and this can be very useful information, allowing it to solve some instances in time where bidirectional Dijkstra uses time.
Considering the case of “easy” instances with instance-complexity we show that bidirectional Dijkstra is instance-optimal for undirected graphs, also in the order-dependent model. Thus, if an undirected graph is easy for any good algorithm, then it is equally easy for bidirectional Dijkstra.
For easy instances, we also have improved an instance-optimality ratio for directed graphs. If a graph has instance-complexity and at most vertices of degree bigger than , then the instance-optimality ratio is . This bound is much better than our bound, for if , then . We also note that , so is no worse than , but typically much better because there are often only few vertices of degree close to in real-world graphs [Bar13, Section 4.5], e.g., on all scale-free networks. Consequently, bidirectional Dijkstra achieves instance-optimality up to polylogarithmic factors on such networks if they admit an solution.
Valid weights. Like in , our main focus in this paper is on graphs with positive real weights. Let denote the distance from s to u. What we really need is that for any vertices u and v, if , then there should be a valid weight (which could be used on an alternative length-2 path from u to v). This means that our results also apply to instances with positive floating point numbers as long as they have not used the full precision allowed in valid weights. Likewise they hold if we say that valid weights are all non-negative integers, but we only consider the instance-optimality ratio on instances with positive integer weights.
In they show that these restrictions are necessary for the instance-optimality of bidirectional Dijkstra. If we consider instances with a smallest valid positive weight, e.g., if the valid weights are the positive integers, then the instance-optimality ratio is . Note that for , this is worse than our general bound. Also, they show a lower bound of for the instance-optimality ratio of any algorithm if we consider instances with weights zero.
These negative results from are all for multigraphs, but they are quite easily translated to simple graphs.
No degree-query. We will also consider what happens if there are no degree-queries. In that case it is most natural to say that edges are in a real linked list where you pay every time you visit the next edge. Thus you will only know the degree when you get to the last edge. This is, in fact, one of the most classic representation of a graph, and bidirectional Dijkstra works for this representation. Table 2 summarizes our results on the instance-optimality ratio when degree queries are unavailable.
Corresponding to the order-dependent model, for any given graph instance G, we consider the worst performance of bidirectional Dijkstra (or any other algorithm that we study instance-optimality for) over all possible orderings of the incidence lists. However, for the instance-complexity, we consider the best time over all possible orderings of the incidence list. This includes the ordering an order-dependent algorithm would have chosen, but this way, a good algorithm has to visit the whole list to determine the degree. Even in this strong model, we will show that bidirectional Dijkstra is instance-optimal on undirected graphs, but is not instance-optimal on directed graphs.
Corresponding to the order-oblivious model, we will consider the expected performance where the incidence lists are randomly ordered. We show that, bidirectional Dijkstra is instance-optimal on all positively real weighted directed and undirected graphs. Note that this is the strongest model for lower bounds, and here we also show that the negative bounds with other weights still hold for simple graphs. That is, if we have zero-weights, then no algorithm can have instance-optimality ratio below , and if we study instances with a minimal positive weight, then the instance optimality ratio is . Here we cannot just use the construction from , for in the order-oblivious case, they used degrees to code vertex indices, but the issue is simple to fix.
1.3 Paper Organization
We start by revisiting the details and correctness of bidirectional Dijkstra in Section 2. Next, we set up the general framework for our analysis in Section 3.
In Section 4, as our first result, we present our main positive answer to the open problem from ; namely that bidirectional Dijkstra is instance-optimal on undirected graphs in the order-oblivious model.
Afterwards, in Sections 5 to 7, we present our main negative answers, proving lower bounds on the instance-optimality ratio in the remaining settings. We present these negative results in the order that we deem easiest to follow technically, covering order-dependent directed graphs in Section 5, order-oblivious directed graphs in Section 6, and order-dependent undirected graphs in Section 7.
Furthermore, in Section 8, we present additional positive results, giving upper bounds on the instance-optimality ratio that in many cases match our lower bounds, as well as strong upper bounds for easy instances.
Then in Section 9, we present our results when degree queries are unavailable. In Section 10, we briefly discuss the cases where zero-weight edges are allowed, or the input graph is promised to have a smallest valid positive edge weight.
2 Revisiting the Bidirectional Dijkstra's Algorithm
Since we will investigate the instance-optimality of bidirectional Dijkstra in this paper, we revisit the algorithm in this section.
As mentioned earlier, bidirectional Dijkstra was first described in [Dan63, Section 17-3.B], albeit only briefly and without a formal correctness proof. More detailed descriptions of the algorithm, together with several variants and their analyses, were later presented in [Nic66, Poh69].
2.1 Dijkstra's Algorithm
At a high level, bidirectional Dijkstra runs the standard Dijkstra's algorithm from the source vertex s (the forward search) and the target vertex t (the backward search) simultaneously. We present the pseudocode for the forward search in Algorithm 1. The backward search is analogous, except that it traverses incoming edges instead of outgoing edges.
Algorithm 1: Forward(s)
Input: graph , source vertex s // backward: target vertex t 1 ; // backward: , 2 Open s // backward: open t 3 while an open vertex exists do 4 among all open vertices x // backward: select minimizing 5 Close and open all unclosed out-neighbors of // backward: replace out- by in-neighbors 6 for each out-neighbor x of do 7 // backward: relax via in-edge
To describe the forward search in more detail, Dijkstra's algorithm maintains a tentative distance from the source vertex to each vertex . Initially, , while for every . The value can be interpreted as the length of the shortest path from to discovered so far and therefore serves as an upper bound on the true shortest-path distance .
Moreover, Dijkstra's algorithm assigns each vertex one of three states: open, closed, or unlabeled. Initially, the source vertex is open, and every other vertex is unlabeled. The algorithm repeatedly selects the open vertex with the smallest tentative distance and closes it. For every unlabeled out-neighbor of , the algorithm changes its state to open. It then relaxes every outgoing edge for such by updating , where denote the weight of edge . Updating implies that a shorter path from to through is found. The basic Dijkstra's algorithm terminates when no open vertex exists, and regards as the true distance for all vertices .
By the correctness of Dijkstra's algorithm, we have the following lemma:
Lemma 2.1 ([Nic66]). In both the forward and backward searches, Dijkstra's algorithm maintains the following invariants:
(a) Every closed vertex has exact tentative distance. That is, for every forward-closed vertex , and for every backward-closed vertex .
(b) Vertices are closed in nondecreasing order of their true distances. That is, if u is forward-closed before v, then ; if u is backward-closed before v, then . Equivalently, when a vertex v is forward-closed (resp. backward-closed), every vertex u satisfying (resp. ) has already been forward-closed (resp. backward-closed).
2.2 Bidirectional Dijkstra
As mentioned above, bidirectional Dijkstra performs a forward search from the source vertex s and a backward search from the target vertex t simultaneously. Different variants of bidirectional Dijkstra differ in how they alternate between the forward and backward searches (e.g., after relaxing a single edge or after completing the relaxation of all outgoing edges of a vertex), as well as in their stopping conditions (e.g., terminating when the two searches meet or terminating when a distance threshold is satisfied). We refer the reader to [HHR 25, Dre69] for a brief overview of these variants.
In particular, proposes a variant that alternates between relaxing one edge in the forward search and one edge in the backward search, and terminates once , where denotes the length of the shortest path found so far.
Initially, . Whenever the algorithm relaxes an edge, it also updates if a shorter path is discovered. For example, when relaxing an edge in the forward search, the algorithm additionally updates
This is because is the length of the shortest path currently known that passes through the edge . If this length is shorter than , then a shorter path has been found, and we therefore update accordingly. Note that this length is if . An analogous update is performed whenever an edge is relaxed in the backward search.
When the termination criterion is satisfied, the algorithm can certify that no path shorter than exists. It therefore terminates and returns . We present the pseudocode of the algorithm in Algorithm 2. Now each vertex maintains an independent state (open, closed, or unlabeled) in each of the forward and backward searches. proves that the algorithm is instance-optimal up to a constant factor when the class of valid inputs consists of all weighted multigraphs, whether directed or undirected.
2.3 Fixed Minor Error From
Note that the bidirectional Dijkstra algorithm presented in Algorithm 2 differs slightly from the one in . Specifically, the pseudocode in updates upon relaxing an edge only when both endpoints and have been closed in the forward and backward searches, respectively (see Line 25 of Algorithm 2 in ). For example, when relaxing an edge in the forward search, the vertex is already forward-closed, and the algorithm in updates according to Equation (3) only if is also backward-closed. In contrast, our algorithm in Algorithm 2 performs this update regardless of whether is backward-closed.
As we show next, the extra condition from should not be there as it can invalidate the claimed instance-optimality guarantee. To see this, consider the instance in Figure 1, where edge labels denote weights. Here has outgoing edges and has incoming edges, while no path connects to . The shortest path is , of length 3.

Figure 1: A counterexample arising from a minor error in . The numbers on the edges denote their weights.
An instance-smart algorithm only needs to inspect the neighborhoods of , , and to certify that this path is optimal, and therefore terminates in time. In contrast, under the update rule of [HHR], after relaxing all outgoing edges of , both and have tentative distance 1, so either vertex may be selected as the next forward-closed vertex. If is selected, then when the edge is relaxed in the backward search, cannot be updated because has not yet been forward-closed. As a result, the algorithm must relax all outgoing edges of before can be updated and the stopping condition can be satisfied, resulting in time on this instance.
Technically speaking, the proof of the instance-optimality of bidirectional Dijkstra on weighted multigraphs (Theorem 5.1 in ) implicitly relies on the property that
Algorithm 2: Bidirectional Dijkstra's Algorithm
Input: graph , source vertex s, target vertex t Output: length of the shortest path from s to t
1 ; // initialize forward search from s 2 ; // initialize backward search from t 3 Mark s as forward-open and t as backward-open 4 // length of the shortest path that we have found so far ( unless ) 5 , // vertices currently being explored in the two executions 6 7 while do 8 // relax one edge in forward search: 9 while do 10 if there is no forward-open vertex then return 11 among all forward-open vertices x 12 Mark as forward-closed 13 14 if then return 15 , and mark x as forward-open if it is not forward-closed 16 17 18 19 // relax one edge in backward search: 20 while do 21 if there is no backward-open vertex then return 22 among all backward-open vertices y 23 Mark as backward-closed 24 25 if then return 26 , and mark y as backward-open if it is not backward-closed 27 28 29 30 return
holds for every edge relaxed by the forward search and every relaxed by backward search. However, this property does not hold under the update rule of . We will discuss this with more details later in Lemma 2.3.
This minor error is resolved by removing the additional condition that requires x to be backward-closed before is updated, as shown in Algorithm 2. Below we will first prove the correctness of our algorithm, and then show that it satisfies the above property. This fixes the minor error in the proof of and establishes its claimed instance-optimality on weighted multigraphs.
2.4 Correctness of Bidirectional Dijkstra
The above-mentioned minor error introduces only unnecessary running time but does not affect the correctness of bidirectional Dijkstra. The correctness proof is essentially identical to that in . For completeness, we briefly present it below.
Recall that denotes the true shortest-path distance from s to t. We assume without loss of generality that . Otherwise, either s = t or no path exists from s to t, in which case the correctness of Algorithm 2 is immediate.
We aim to show that Algorithm 2 returns . At the termination of Algorithm 2, we have . Since and are forward- and backward-closed, respectively, Lemma 2.1(a) gives
We assume for contradiction that , and fix a shortest path . Let be the last vertex on with , and let be the successor of on . By Lemma 2.1(b), is forward-closed. Moreover, , which together with Equation (4) implies
Since lies on the shortest path , , and thus Equation (5) yields . By Lemma 2.1(b), is backward-closed.
Since and are forward-closed and backward-closed respectively before termination, the edge has been relaxed by both the forward search (when is closed) and by the backward search (when is closed), both before termination. At the later of these two events, both and hold, so the update rule for in Algorithm 2 yields , a contradiction.
2.5 Properties of Bidirectional Dijkstra
We now summarize some known properties of bidirectional Dijkstra that will be used later.
Visiting vertices and edges. We say that an edge is visited by an algorithm if, during its execution, either OUT or IN is invoked at u or v and returns the other. We say that a vertex v is visited by an algorithm if, during its execution, either INDEG(v) or OUTDEG(v) is invoked, or if at least one incident edge of v is visited. Since each query causes vertices and edges to be visited, the total number of vertices and edges visited by any algorithm is asymptotically equal to the total number of query operations the algorithm performs.
Edge sets and of bidirectional Dijkstra. We now define and to be the sets of edges visited by the forward and backward searches, respectively, in the bidirectional Dijkstra's algorithm shown in Algorithm 2. For undirected graphs, we define to be the set of ordered pairs of vertices such that the edge is visited by the forward search at , and define symmetrically. We have
Lemma 2.2. . The number of queries performed by Algorithm 2, as well as the total number of visited vertices and edges, is .
Proof. Algorithm 2 alternates edge relaxations between the forward and backward searches, starting with the forward search. Therefore, is initially 0 and alternates between 1 (after a forward relaxation) and 0 (after a backward relaxation) throughout the execution. Consequently, and differ by at most one.
Consider the number of vertex and edge queries visited by Algorithm 2. A vertex will be considered visited the first time it is marked open, and (except for s and t) a vertex is marked as open only after one of its incident edges has been relaxed. Hence, the number of visited vertices is asymptotically no larger than the number of relaxed edges. Therefore, the total number of visited vertices and edges is . Since by definition each visited vertex or edge incurs only query operations, the total number of queries performed by Algorithm 2 is also .
Vertex sets and of bidirectional Dijkstra. Moreover, we define to be the set of forward-closed vertices from which at least one outgoing edge has been visited by the forward search, and to be the set of backward-closed vertices into which at least one incoming edge has been visited by the backward search. Note that the last vertex selected as or , which triggers the termination criterion (i.e., Line 14 or Line 25 of Algorithm 2), is not included in or , since the termination criterion is checked before any edge incident to the newly selected vertex is visited. By definition, for any edge , we have ; analogously, for any edge , we have .
Lemma 2.3. For any and , .
Proof. Let denote the event that happens at the first time. Consider the moment that happens. Clearly, can only happen when we update (in Lines 18 or 29), or when we update or (in Lines 11 or 23). By symmetry, we assume that it happens in either Line 18 or Line 11.
In the latter case, the algorithm will terminate immediately before relaxing any other edges, so . Let denote the old right before happens in Line 11, then . By Lemma 2.1, for any , and for any . By the correctness of bidirectional Dijkstra, . Therefore for any and .
It remains to prove that cannot happen in Line 18. Assume for contradiction that it happens in Line 18. When it happens, must be strictly decreased, so . We also have . This is because, for any vertex , whenever we update or , we will immediately update . Therefore, we have
Since , we also have .
At this point, is backward-closed, so by Lemma 2.1(b), was already backward-closed and all incoming edges backward-relaxed. In particular, . Again, since the algorithm updates whenever either or is updated for any vertex , it follows that before Line 18 we already had . Thus Line 18 could not have strictly decreased , a contradiction.
3 Setting Up the Analysis Framework
In this section, we set up the framework for establishing our upper and lower bounds on the instance-optimality ratio as shown in Table 1. Recall from Equation (1) that the instance-optimality ratio
The algorithm in [HHR 25] does not satisfy this property due to the additional condition on updating .
We remark that this is the only place where this proof does not extend to graphs with zero-weight edges.
of an algorithm A is defined as
where denotes the expected number of queries made by A on instance I, and is the instance complexity of instance I, defined as the minimum value of over all good algorithms A.
3.1 Lower Bounds
To establish an lower bound on the instance-optimality ratio of bidirectional Dijkstra, we construct counterexamples exhibiting instances on which an instance-smart algorithm solves the shortest-path problem faster than bidirectional Dijkstra by at least a factor of .
To establish an lower bound on the instance-optimality ratio of all algorithms, we show that for every good algorithm A, there exists an instance on which an instance-smart algorithm performs significantly faster than A by at least a factor of .
3.2 Upper Bounds
In Lemma 2.2, we established a tight bound on the expected number of queries made by bidirectional Dijkstra. In the following sections, we will establish lower bounds on the instance complexity, thereby obtaining upper bounds on the instance-optimality ratio of bidirectional Dijkstra.
To construct the lower bound on the instance complexity, we for now fix a valid graph instance G and an arbitrary good algorithm A. The algorithm A may be randomized, with its randomness determined by a random seed R. But once the random seed R is fixed, the execution of A on G is completely determined by the answers it receives from the graph oracle. Let denote the execution of A with the random seed R. If there exist two graphs G and on which receives the same answers to all its queries, then produces exactly the same output on G and .
The main idea of our proof is to construct another graph whose structure differs from that of G only on a small fraction of the graph (typically just a constant number of vertices and edges), which A avoids. At the same time, is carefully constructed so that the shortest-path distance from s to t differs between G and .
Specifically, we use the expected number of vertices and edges visited by bidirectional Dijkstra as the basis of our analysis. Recall from Section 2.5 that each query operation visits only vertices and edges. Therefore, the number of vertices and edges visited by bidirectional Dijkstra is asymptotically equivalent to the number of queries it performs, namely as shown in Lemma 2.2.
We assume for contradiction that A, as a good algorithm, visits significantly fewer vertices and edges than bidirectional Dijkstra. We then prove that, with constant probability, A does not visit the region where differs from G. Here, the probability is taken over the choice of the random seed used by A. Consequently, with constant probability, all query answers received by A are identical on G and , implying that A will incorrectly produce the same shortest-path output on G and with constant probability. This contradicts the assumption on the goodness of A.
To formalize the above idea, we define as the probability that visits edge on , and as the probability that visits vertex on . Moreover, for any , we say an edge is -bad to (or simply -bad or bad if the context is clear; similarly below) if ; otherwise it is -good. Analogously, we say a vertex is -bad if ; otherwise it is -good. For ease of presentation, we say that a vertex or an edge is -bad if it is -bad for some constant .
Note that in the order-dependent model, the probability is taken over the random seed used by A. In the order-oblivious model, the probability is additionally taken over the ordering of the vertices returned by the graph oracle in response to the neighbor queries IN and OUT, where the ordering is chosen uniformly at random. We therefore have the following lemma.
Lemma 3.1. In the order-oblivious model, if an edge is p-good, then either every out-edge of u is q/4-good or every in-edge of v is q/4-good.
Proof. The edge is queried either as an out-edge of u or as an in-edge of v. Suppose without loss of generality that e is queried as an out-edge of u with probability at least q/2.
Let be the set of edges queried as out-edges of , and fix another out-edge of . Fix the randomness of the algorithm and some order of the adjacency lists. If but , then swapping and in the out-going adjacency list of results in being queried, since the algorithm behaves identically until this query. Since all orderings are equally likely, averaging over all randomness gives . Therefore,
Since was arbitrary, every out-edge of u is queried with probability at least q/4.
Lemma 3.2. In the order-oblivious model, an edge is 4q-bad if u has at least one q-bad out-edge and v has at least one q-bad in-edge.
Proof. Lemma 3.2 follows directly from Lemma 3.1. Indeed, suppose for contradiction that edge is 4q-good. Then, by Lemma 3.1, either every out-edge of u is q-good or every in-edge of v is q-good, yielding a contradiction.
We further define as the expected number of vertices and edges in G visited by A, that is,
We may omit G or both A and G in the subscripts when the context is clear.
We construct in one of the following ways, under the assumption that A visits a significantly smaller total of vertices and edges than bidirectional Dijkstra when solving the shortest-path problem. Let and denote the lengths of the shortest s-t path in G and , respectively. In each construction, we ensure that , and that differs from G only by (i) removing a constant number of -bad edges, (ii) adding a constant number of new edges, and thereby (iii) changing the degrees of a constant number of -bad vertices. By the union bound, the probability that A visits at least one vertex or edge where differs from G is at most a constant. Consequently, A receives exactly the same query answers on both G and with constant probability (e.g., 1/2 as we use in our proof). This contradicts the assumption that A is a good algorithm that outputs the correct answer on every instance with probability at least 9/10.
Construction (a). We construct by finding an -length path from a vertex to a vertex in such that every edge on is -bad. Recall that Lemma 2.3 shows that . We then decrease the edge weights along to obtain such that . In this construction, and differ only on a few -bad edges on the path , and the degrees of all vertices remain unchanged.
Construction (b). There may be no suitable path in , in which case we construct one by swapping edges. Specifically, we find an outgoing edge with and an incoming edge with , such that both and are -bad edges. We then replace and with and while preserving the degrees of all vertices. This is possible provided that neither nor already exists in . Note that certainly does not exist; otherwise, we could simply apply Construction (a). Such an edge swap creates a one-hop path from to , while modifying only two bad edges, adding two new edges, and preserving the degrees of all vertices. Moreover, on directed graph, it does not change the shortest-path distance from to any vertex in , or from any vertex in to . We then apply Construction (a) to obtain such that .
Construction (c). We may also modify bad vertices. Specifically, we select a bad vertex and find an outgoing edge with and an incoming edge with , such that both and are -bad edges. We remove the edges and , and add the edges and . We further add edges incident to and from other bad vertices so as to preserve the degrees of all vertices except these bad vertices. We then apply Construction (a) to construct such that .
4 Order-Oblivious Instance-Optimality for Undirected Graphs
In this section, we show that bidirectional Dijkstra is instance-optimal for undirected graphs in the order-oblivious model, thus positively answering the open question left by regarding the instance-optimality of bidirectional Dijkstra on simple weighted graphs.
Theorem 4.1. In the order-oblivious model, Algorithm 2 is instance-optimal on undirected graphs.
Proof. We adopt the Construction (a) and (b) from Section 3 to construct .
Recall from Lemma 2.2 that the total number of vertices and edges visited by Algorithm 2 is , where and denote the set of edges visited by the forward and backward searches in Algorithm 2, respectively. Assume for contradiction that , where we recall from Equation (8) that denotes the expected number of vertices and edges visited by A. Since a q-bad edge satisfies , the assumption implies that there exist at least one 1/20-bad edge and at least one 1/20-bad edge .
If are not all distinct, then since this is for undirected graphs, and are already connected by at most two 1/20-bad edges, completing Construction (a).
Otherwise, are all distinct. Note we are considering the order-oblivious model, in which the orders of the vertices and the incident edges are chosen uniformly at random. By Lemma 3.2, if there exists an edge between a vertex in and a vertex in , then this edge must be 1/5-bad since each of its endpoints has an incident 1/20-bad edge. Hence, and are connected by one 1/5-bad edge and at most two 1/20-bad edges. Otherwise, there is no edge between and . We then replace by , completing Construction (b).
We remark that Theorem 4.1 shows the only setting in which bidirectional Dijkstra is instance-optimal over all valid instances. In all other settings, it is off by a super-polylogarithmic factor, as we will see in the following sections.
5 Order-Dependent Instance-Non-Optimality for Directed Graphs
We now begin presenting our lower bounds on the instance-optimality ratio. For ease of exposition, we present our results in technical order. In this section, we focus on directed graphs in the order-dependent model. The lower bounds for directed graphs in the order-oblivious model and for undirected graphs in the order-dependent model will be given later in Section 6 and Section 7, respectively.
Recall that in the order-dependent model, the orders of the vertices and their incident edges are part of the input and may therefore be exploited by an instance-smart algorithm. However, an algorithm that aims to be instance-optimal (e.g., bidirectional Dijkstra) must be the best under every possible ordering. We therefore regard the ordering as being chosen adversarially, and compare its query complexity against that of instance-smart algorithms tuned for this ordering.
We prove the following lower bound, when parameterizing in the number of vertices n and the number of edges m.
Theorem 5.1. In the order-dependent model, the instance-optimality ratio of every algorithm is on directed graphs.
This result will essentially follow from the proof of the following lower bound, parameterized in the number of vertices n and the maximum in- and out-degree .
Theorem 5.2. In the order-dependent model, the instance-optimality ratio of every algorithm is on directed graphs.
In Section 8, we will show that the upper bound on the instance-optimality ratio of bidirectional Dijkstra matches the above lower bounds for every algorithm. Consequently, bidirectional Dijkstra is the best possible algorithm in terms of instance-optimality ratio on directed graphs in the order-dependent model.
Proof of Theorem 5.2. Recall from Section 3.1 that we establish lower bounds on the instance-optimality ratio of all algorithms by showing that for every good algorithm A, there exists an instance on which an instance-smart algorithm performs significantly faster than A.
For any given , consider the following graph instance which has vertices and maximum degree .
The graph consists of several components: , where for , and . The target vertex together with forms an outgoing path starting from . Each vertex except and those in has an outgoing edge to every vertex in , and each vertex except and those in has an incoming edge from every vertex in . In addition, the source vertex has an outgoing edge to every vertex in , each of weight 1. The target vertex has an incoming edge from every vertex in , each of weight 1. Finally, there is a perfect matching from to . A sketch for the above graph construction is given in Figure 2.
An instance-smart algorithm first visits all incident edges of s and t. From this, it learns the in- and out-degrees of the vertices in , as well as the existence of a path from t to . By visiting all incident edges of the vertices in , the algorithm verifies that is disconnected from the remaining components of the graph.
From the out-degrees of the vertices in and the in-degrees of the vertices in , the algorithm concludes that there are no outgoing edges from and that . Similarly, there are no incoming edges to and . Consequently, if there exists an path, then no vertex in can lie on any shortest path.

Figure 2: Lower-bound construction for directed graphs in the order-dependent model. A blue block arrow from a set X to a set Y indicates that every vertex in X has a directed edge to every vertex in Y.
Moreover, by comparing the in-degree of each vertex in with the total number of vertices , together with the fact that neither nor any vertex in has an edge to , the algorithm concludes that every vertex other than and those in has an outgoing edge to every vertex in . Analogously, every vertex other than and those in has an incoming edge from every vertex in . Combining this information with the out-degrees of the vertices in , the algorithm concludes that, for each vertex , at most one outgoing edge of needs to be visited in order to solve the shortest-path problem. Let denote this edge, and let denote the position of in the outgoing adjacency list of , that is, . The instance-smart algorithm tuned for this instance first queries . Since it has already visited all vertices in , it can verify whether the returned vertex belongs to . Once it confirms that , it knows that this is the unique outgoing edge of outside , and therefore no further out-neighbor queries from are necessary.
Consequently, the instance-smart algorithm visits only one outgoing edge of each vertex in and one incoming edge of each vertex in , after which it can compute the shortest s-t path. The total number of vertices and edges visited is therefore .
In contrast, for an algorithm that aims to be instance-optimal, as explained above, we should regard the order of the edges in the outgoing adjacency lists of the vertices in as being chosen adversarially. Consequently, for each vertex , the algorithm makes queries in expectation before encountering the edge , where the expectation is taken over the internal randomness of the algorithm. A symmetric argument applies to the incoming adjacency lists of the vertices in . Since every outgoing edge from to a vertex in and every incoming edge from a vertex in to has identical weight 1, the algorithm must query all edges from to to ensure that none of them yields a shorter path. This results in a total of queries.
A small modification of this proof gives us Theorem 5.1.
Proof of Theorem 5.1. The lower-bound construction for Theorem 5.2 yields a graph with edges. We now have a given . So we set for each , so that the resulting graph has edges. The proof then follows directly from the above construction.
6 Order-Oblivious Instance-Non-Optimality for Directed Graphs
We move on to the setting of directed graphs in the order-oblivious model. We start with our lower bound for every algorithm. When parameterizing in n and m, we again show a lower bound of
for every algorithm, but only when the average degree is . We will later show an lower bound without the assumption on the average degree, when restricting attention to bidirectional Dijkstra.
Theorem 6.1. In the order-oblivious model, the instance-optimality ratio of every algorithm is on directed graphs with .
Proof. The case is trivial, so we assume that . Since , we have .
We construct the graph shown in Figure 3. The graph has several components: . Let and , (not pictured) so that . Pick vertices , , , , , and . The vertices in form a path ending at , and the vertices in form a path starting at . Moreover, has an outgoing edge to every vertex in , and every vertex in has an outgoing edge to . Every vertex in has an edge to every vertex in , apart from the edge which is left absent. Similarly, every vertex in has an edge to every vertex in , apart from the edge which is left absent. Finally, edges and are present. The number of edges is . To construct the modified graph from , remove (red dashed) edges and add (green) edges .

Figure 3: Lower-bound construction for directed graphs in the order-oblivious model. A blue block arrow from a set X to a set Y indicates that every vertex in X has a directed edge to every vertex in Y, except that the edges and are absent from G. Red dashed edges are present in G but absent from , while green edges are present in but absent from G.
An instance-smart algorithm can verify that is not reachable from in as follows. Identify as the set of out-neighbors of an arbitrary out-neighbor of . Observe that every vertex in has in-degree with no in-edges from , other than one vertex, , which has in-degree due to the additional missing in-edge from . Walk to from by following the unique in-edge for a number of steps known to the instance-smart algorithm. Query every out-neighbor of to find, that it has no out-neighbor in . Furthermore, one of these out-neighbors will be identifiable as the one outside . Similarly find .
Observe that no out-edge from goes to , and recall that we have observed that is absent. Combining this with the degrees of the vertices in certifies, that every vertex outside has edges to . Finally, walk to every out-neighbor of , i.e. every vertex in , and observe that all out-degrees are . This certifies that all out-edges of go to , which we know has no out-edges by querying out-degrees. This certifies that no edge going out of exists, and thus, that no path from to exists. This can all be done with instance-complexity .
Note that it is crucial that the instance-smart algorithm “knows” exactly how many steps to walk from s along the path before reaching (or, symmetrically, from t before reaching ). This number of steps acts as a kind of “lucky number” tailored to this particular instance. Regardless of whether the input graph is G or not, the instance-smart algorithm can simply walk this many steps along the path and then check whether it encounters the edge (or ). On the instance G, this allows the instance-smart algorithm to run in only queries.
In contrast, an algorithm that aims to be instance-optimal on all instances cannot rely on such instance-specific “lucky numbers.” Knowing a number that is useful only for a single instance does not help improve the instance-optimality ratio, since the algorithm must, on every instance, achieve a running time no more than a factor of the instance-optimality ratio larger than that of every instance-smart algorithm tuned to the corresponding instance. As a result, such an algorithm needs to consider the choices of vertices from their respective sets as adversarial. This is essentially equivalent to assuming that are chosen uniformly at random from their respective sets. In the following, we show that any such algorithm requires queries on this construction of .
Consider the execution of the algorithm on , where the vertices are chosen uniformly at random from their respective sets and the vertex and edge orders are chosen uniformly at random. Call a query revealing if it visits one of the four dashed red edges , or finds one of the special vertices and . If no revealing query is made, then the algorithm receives exactly the same answers on and on .
We now bound the probability that a revealing query happens before time for some small positive constant . Condition on everything the algorithm has seen so far, assuming no revealing query has happened. Then is still hidden among possible edges from to , except for the positions already ruled out by previous queries. As long as fewer than queries have been made, the next query therefore hits with probability . The same argument applies to .
For the edge , conditioned on not having found , the algorithm has to find both the special vertex and the position of in its outgoing adjacency list. Thus is again hidden among possible remaining choices. The edge is symmetric.
It remains to account for finding or . Finding them by direct vertex queries takes queries in expectation. Since , we have , so this is also . Finding them through an incident edge is already covered by the same argument as above, other than as a neighbor of or , but every vertex in and has relevant degree , so this is no better.
Therefore, at any time before queries, conditioned on no earlier revealing query, the next query is revealing with probability . Summing over the first queries, the probability that the algorithm makes any revealing query is . Choosing small enough, this probability is less than 1/10.
With probability at least 9/10, the algorithm therefore sees the same query answers on G and on , and makes the same output. However, G has no path from s to t, while does. This contradicts that the algorithm is good. So every good algorithm must make queries in expectation on some instance in this family.
Above, in Theorem 6.1, we establish an lower bound on the instance-optimality ratio of every algorithm, under the assumption that . Now, restricting our attention to bidirectional Dijkstra, we show stronger lower bounds by removing the assumption.
First, when parameterizing in n and m, we get the following bound on bidirectional Dijkstra.
Theorem 6.2. In the order-oblivious model, the instance-optimality ratio of Algorithm 2 is on directed graphs.
As in the previous section, this result will follow from the proof of the following bound, which is parameterized in n and the maximum in- and out-degree .
Theorem 6.3. In the order-oblivious model, the instance-optimality ratio of Algorithm 2 is on directed graphs.
Proof. Consider the graph in Figure 2 again. Now we replace the matching from to with only one edge for some and .
The instance-smart algorithm can first query all in-edges and out-edges of vertices in and the in-degrees and out-degrees of all vertices. Then it can find and by their degrees and it also knows that it suffices to find the edge . So it only needs to query all out-edges of . The total time complexity is .
On the other hand, bidirectional Dijkstra will query all out-edges of vertices in and all in-edges of vertices in , so it spends time.
Theorem 6.2 follows from the proof of Theorem 6.3, by setting for .
Let us again mention that, in Section 8, we will give matching upper bounds on the instance-optimality ratio of bidirectional Dijkstra in both parameterizations, implying that the above lower bounds on the instance-optimality ratio of bidirectional Dijkstra are already tight.
7 Order-Dependent Instance-Non-Optimality for Undirected Graphs
The final setting is undirected graphs in the order-dependent model, where we establish lower bounds on the instance-optimality ratio for all algorithms. In particular, when parameterizing by n and m, we obtain the following result.
Theorem 7.1. In the order-dependent model, the instance-optimality ratio of every algorithm is on undirected graphs when .
This result will essentially follow from the proof of the following bound, which is parameterized in n and the maximum in- and out-degree .
Theorem 7.2. In the order-dependent model, the instance-optimality ratio of every algorithm is on undirected graphs.
In Section 8, we will show matching upper bounds for bidirectional Dijkstra, in both parameterizations. Consequently, bidirectional Dijkstra is the best possible algorithm in terms of instance-optimality ratio on undirected graphs in the order-dependent model.
Proof of Theorem 7.2. For any , we construct a graph with vertices and maximum degree as follows.
Analogous to the directed case, the graph consists of several components: , where , , , and so that the number of vertices in the graph is . The edges are defined as follows. The target vertex together with forms a path starting from . The source vertex (respectively, the target vertex ) is connected to every vertex in (respectively, ) by an edge of weight 1. Every vertex in is connected to every vertex in both and . In addition, every pair of vertices within and within is connected by an edge. As a result, the degree of each vertex in is , since it is adjacent to every vertex in the graph except itself and the vertices in . A sketch of the construction is shown in Figure 4.

Figure 4: Lower-bound construction for undirected graphs in the order-dependent model. A blue block line between two vertex sets indicates that every vertex in one set is connected by an edge to every vertex in the other set. A circular blue block line around a vertex set indicates that every pair of vertices within the set is connected by an edge. The green numbers indicate the sizes of the corresponding vertex sets.
An instance-smart algorithm first checks all edges incident to s and t, thereby identifying the sets , , and . It then verifies all edges incident to the vertices in , confirming that they are disconnected from the remaining vertices. It also confirms that s is not adjacent to any vertex in , and t is not adjacent to any vertex in .
Next, the algorithm queries the degree of each vertex in . Comparing these degrees with the total number of vertices , together with the fact that neither nor any vertex in is adjacent to , it concludes that every vertex in is adjacent to every vertex in the graph except itself and the vertices in .
While examining the edges incident to t, the algorithm also observes that all of them, except the edge to , have the same weight. Since every neighbor of t belongs to either or , and no path from t to s can pass through , it concludes that the edge weights within are irrelevant to the s-t distance.
The algorithm then queries the degree of each vertex in . Comparing these degrees with , and using the fact that every vertex in is adjacent to every vertex in the graph except and the vertices in , it concludes that every vertex in is adjacent only to vertices in . Hence, the edge weights of the edges between and are likewise irrelevant to the distance.
Next, the algorithm queries the degree of each vertex in . Comparing these degrees with the total number of vertices , together with the fact that no vertex in is adjacent to , it concludes that every vertex in is adjacent to every vertex in , as well as to every other vertex in .
Finally, from the edges incident to s, the algorithm observes that they all connect to vertices in and have the same weight. It therefore concludes that the edge weights within are also irrelevant to the s-t distance. Consequently, the algorithm only needs to inspect the edge weights of the edges between and . The overall query complexity is therefore .
On the other hand, for any algorithm, it is necessary to query all edges between and to find the one with the minimum weight. For an algorithm that aims to be instance-optimal, as explained before, we should regard the order of the edges in the adjacency lists as being chosen adversarially. Therefore, the expected time complexity is since vertices in have degrees and vertices in have degrees . Therefore, any algorithm must spend time in the worst input.
By a small modification of the above proof, we get Theorem 7.1.
Proof of Theorem 7.1. The proof follows from the proof of Theorem 7.2. Note that the graph we constructed in the proof of Theorem 7.2 has edges. We now have a given for the number of edges in the graph, and we set for .
8 More Instance-Optimality
In this section, we present upper bounds on the instance-optimality ratio of bidirectional Dijkstra, in all settings other than that of order-oblivious undirected graphs, which we have already covered in Section 4.
Comparing these upper bounds with the lower bounds established in Sections 5 to 7, we note that our analysis of bidirectional Dijkstra is tight in all settings. More surprisingly, bidirectional Dijkstra achieves the asymptotically best possible instance-optimality ratio among all algorithms in every setting, except that of order-oblivious directed graphs, where our results are inconclusive.
Additionally, we show strong upper bounds on the instance-optimality ratio of bidirectional Dijkstra on easy instances, i.e. instances with low instance-complexity.
8.1 Directed Graphs
We begin by presenting our upper-bound results for directed graphs. These results are stated in the order-dependent model and, as discussed in Section 1.1, also hold in the order-oblivious model.
When parameterizing in n and m, we get the following upper bound.
Theorem 8.1. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on directed graphs.
If we instead parameterize in n and , we get the following upper bound.
Theorem 8.2. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on directed graphs.
Finally, if we restrict to easy instances, we get the following upper bound.
Theorem 8.3. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on directed graphs when there are at most vertices with degree .
In the following, we will first prove Theorem 8.2, building on which we prove Theorem 8.1 and Theorem 8.3.
8.1.1 Proof of Theorem 8.2
Proof of Theorem 8.2. The proof builds on several lemmas. First, we claim
Lemma 8.4. If , then .
Proof. We assume for contradiction that . We will then be able to apply either Construction (a) or Construction (b) from Section 3 to construct a graph such that , while produces the same output on both and with probability at least 1/2. This contradicts the assumption that is a good algorithm that outputs the correct answer on every instance with probability at least 9/10. The details are given below.
Since , at least edges in are 1/4-bad. Otherwise, at least edges in would be 1/4-good, contributing more than to , a contradiction. Similarly, at least edges in are 1/4-bad. Fix one such edge . There are at most edges satisfying , and at most another edges satisfying . We call these at most edges forbidden edges for future reference.
Since , it follows that . Therefore, at least edges in are 1/4-bad. Excluding the at most forbidden edges, at least 1/4-bad edges remain. Fix one such remaining edge .
If or , then there is already a bad edge from to . We therefore apply Construction (a) from Section 3 to construct . Otherwise, if , then the two 1/4-bad edges already form a path from to . Again, we apply Construction (a) to construct .
In the remaining case, we apply Construction (b) by replacing and with and . This completes the proof.
Furthermore, we claim
Lemma 8.5. If , then .
Proof. We assume for contradiction that . We will then be able to apply Constructions (a) and (c) from Section 3 to construct . We consider the two cases and separately, as described below.
Case . Since , there exist a 1/10-bad edge and a 1/10-bad edge . Since , there exists at least one 1/20-bad vertex . If already exists, we leave it unchanged. Otherwise we remove the edge and add the edge . We do similar to to connect .
In particular, consider the vertex . Since , there are at least vertices that are not in-neighbors of . Among them, there exists a 1/10-bad vertex , since . We add the edge to restore the in-degree of . By a symmetric argument, there exists a 1/10-bad vertex that is not an out-neighbor of , and we add the edge to restore the out-degree of .
As a result, the degrees of at most one 1/20-bad vertex and two 1/10-bad vertices are modified, and at most two 1/10-bad edges are removed. But now we have a length-two path connecting and , thereby completing Construction (c).
Case . We have
Similarly, . Hence, there exist a 1/5-bad vertex and a 1/5-bad vertex . If exists, we reduce its edge weight so that . Otherwise, we add and set its edge weight so that .
Combining Lemmas 8.4 and 8.5 gives Theorem 8.2.
8.1.2 Proof of Theorem 8.1
Proof of Theorem 8.1. The proof builds on the following lemma, which is analogous to Lemma 8.5, but we now consider m instead of .
Lemma 8.6. If , then .
Proof. Assume for contradiction that . Let denote the set of 1/10-bad vertices, then . Let be an arbitrary vertex in . We are going to connect to (some vertex in) . Since , at least half of the edges in are 1/10-bad. These edges come from at least different vertices, as each vertex can have at most edges to .
- If , then at least one of these vertices has an out-degree of at most . So there exists a 1/10-bad edge such that the out-degree of is no larger than . If or , we are done. Otherwise we replace with , and then fix the out-degree of . Since , we can add an edge for some .
• If , then . So . Let . If or , we are done. Otherwise we add the edge .
In both cases, we connect to some . Symmetrically, we connect some to . Then we connect to through . We then apply Construction (a) to construct .
Combining Lemma 8.6 and the fact that gives Theorem 8.1.
8.1.3 Proof of Theorem 8.3
Proof of Theorem 8.3. Recall that in Theorem 8.3, we are going to prove that in the order-dependent model, the instance-optimality ratio of Algorithm 2 is on directed graphs when there are at most vertices with degree at least . Here we recall that denotes the instance-complexity. We are going to prove that , which in turn implies the desired instance-optimality ratio of Algorithm 2.
Let denote the set of 1/10-bad vertices in . Then every vertex in is visited by with probability at least 1/10. Therefore, the instance-complexity satisfies , or equivalently, .
Let denote the set of vertices whose in- or out-degree is at least , then . Let . Since every vertex in has at most in-edges from vertex in , we have . Similarly, we define and have .
Lemma 8.7. Either all edges in are 1/10-good, or all edges in are 1/10-good.
Proof. Assume for contradiction that there are 1/10-bad edges and . Let be an arbitrary vertex in . We are going to connect to . If or , we are done. Otherwise we replace with , and then fix the in-degree of . Since , the indegree of is thus less than , so we can add an edge for some . Symmetrically, we connect to . Then we are able to apply Construction (a) to construct .
By Lemma 8.7, . On the other hand, since otherwise there are two bad vertices in and respectively. So .
8.2 Undirected Graphs
We now present our upper-bound results for undirected graphs. Again, these are stated in the order-dependent model, but also hold in the order-oblivious model by definition.
We first get the following upper bound when parameterizing in n and m.
Theorem 8.8. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on undirected graphs.
If we instead parameterize in n and , we get the following upper bound.
Theorem 8.9. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on undirected graphs.
Finally, if we restrict to instances with instance-complexity , then we have
Theorem 8.10. In the order-dependent model, Algorithm 2 is instance-optimal on undirected graphs with .
In the following, we will first prove Theorem 8.10, building on which we prove Theorem 8.8 and Theorem 8.9.
8.2.1 Proof of Theorem 8.10
Proof of Theorem 8.10. The proof builds on the following lemma.
Lemma 8.11. If , then .
Proof. We assume for contradiction that . Then there must exist a 1/10-bad vertex . Since , there must exist 1/10-bad edges and .
If are not all distinct, then and are already connected by bad edges. Then we are able to apply Construction (a) to construct .
Otherwise, we are going to connect with (and symmetrically connect with ). If or , then is already connected to . Otherwise, we can replace by , without changing the degrees of and . Then we are able to apply Construction (b) to construct .
Lemma 8.11 directly implies the Theorem 8.10.
8.2.2 Proof of Theorem 8.8 and Theorem 8.9
The proofs build on the following lemma.
Lemma 8.12. If , then .
Proof. For a 1/10-bad edge , we say it is very bad if (1) there is another 1/10-bad edge such that , or (2) is a 1/10-bad vertex. We symmetrically define very bad edges in . Since , at least half of the edges in are 1/10-bad, and there are at most 1/10-good vertices. For each of these 1/10-good vertices, it has at most one incident edge that is a 1/10-bad edge in but not very bad. Therefore, at least 1/8 of the edges in are very bad. Similarly, at least 1/8 of the edges in are very bad.
Let be the set of quadruples such that is a very bad edge in and is a very bad edge in . Then
The next step is to give an upper bound of .
Claim 8.13. For any , at least one of and is a 1/10-good edge.
Proof. If one of them is a 1/10-bad edge, then is connected to by bad edges. If both of them do not exist, then we can replace by .
Claim 8.14. For any , at least one of and is a 1/10-good edge.
Proof. If one of them is a 1/10-bad edge, then is connected to by bad edges. Now assume both of them do not exist. If both and are 1/10-bad, we can replace by . Otherwise, assume is 1/10-good by symmetry. We replace by . By the definition of very bad edges, we connect some to where is a 1/10-bad edge and . Since , the shortest path from to will not be affected by removing .
By the two claims, the quadruple contains one 1/10-good edge from and one 1/10-good edge from . Any such two edges share an endpoint. Thus some vertex in is incident to two 1/10-good edges within the quadruple. We charge the quadruple to this vertex.
For a vertex , let be the number of 1/10-good edges incident to . Suppose a quadruple is charged to . Then is incident to one very bad edge of the quadruple and to two 1/10-good edges inside the quadruple. There are at most choices for the very bad edge and at most choices for the two 1/10-good edges. Also, there are at most choices for the other very bad edge of the quadruple. So is charged at most times.
We further note that is twice the number of 1/10-good edges. Since each 1/10-good edge is queried with probability at least 1/10, the number of good edges is at most . Summing over all vertices, we get
Combining Equations (9) and (10) proves the lemma.
Proof of Theorem 8.9. If , the theorem follows from Lemma 8.11; if , the theorem follows from Lemma 8.12.
Proof of Theorem 8.8. The instance-optimality ratio of Algorithm 2 is by Lemma 8.11 and , or by Theorem 8.9 and .
8.3 Few high-degree vertices
We now extend our results on the instance-optimality ratio of bidirectional Dijkstra on easy instances by showing that it admits an upper bound of on directed graphs with at most vertices whose in-degree or out-degree exceeds .
Theorem 8.15. In the order-dependent model, the instance-optimality ratio of Algorithm 2 is on directed graphs with at most vertices whose in-degree or out-degree is larger than .
Let be the set of vertices of degree larger than , and write .
Lemma 8.16. If , then .
Proof. Assume for contradiction that . At least edges in are 1/4-bad; otherwise these 1/4-good edges in already contribute more than to . Recalling that , we thus have that at least edges in are 1/4-bad. Since , at most edges have an endpoint in . Avoiding such edges, there remain more than edges in which are 1/4-bad. In particular, there is a 1/4-bad edge with and .
We now find a -bad edge such that and . There are at most edges that do not satisfy this: at most with , since has at most neighbors, and at most of these have degree larger than , and analogously, at most with . Thus, at least edges in are 1/4-bad and satisfy both conditions, so an edge like we were looking for indeed exists. Note that , , and , otherwise we can apply Construction (a) to construct .
If , then the two 1/4-bad edges already constitute a path from to . Otherwise we replace and by and .
Lemma 8.17. If , then .
Proof. Assume, for contradiction, that . Then more than vertices are 1/10-bad.
Case 1. Assume . Since , we have
Similarly, using , we get . So there are 2/5-bad vertices and . If , this gives a bad path from to . Otherwise we add the edge , again giving a bad path. We can then apply Construction (a) to construct , contradicting the assumption that is a good algorithm.
Case 2. Assume the opposite, namely . Since , there are 1/10-bad edges in both and . Let be a 1/10-bad vertex. We will now create a bad path from to through , starting with creating a path from to .
Case 2.1. Assume that there exists a 1/10-bad edge with . If or , we have a bad path from to . Otherwise, replace by . If is 1/10-good, we need to fix its in-degree. Since , the in-degree of is at most , so there is a 1/10-bad vertex with . We can add , fixing the in-degree of . We have now created a bad path from to and changed the degrees of only a few 1/10-bad vertices.
Case 2.2. Assume the opposite, namely that every edge with is 1/10-good. There are fewer than such edges. The remaining edges lie in , so there are at most of them. In total,
If , this implies , and hence
If , then is impossible in the current case, because then and the case assumption would imply that all edges of are 1/10-good, contradicting . So instead, and , in which case , giving again . This means that there is a 1/5-bad vertex in . If or , we already have a bad path from to . Otherwise we add an edge . We have thus again created a bad path from to and changed the degrees of only the 1/5-bad vertices and .
Together, Case 2.1 and 2.2 tell us that we can connect to by a bad path. Symmetrically, we can connect to by a bad path, giving the wished-for bad path from to . By a union bound, distinguishes the modified graph from the original with probability less than , which contradicts the assumption that is a good algorithm that outputs the correct answer on every instance with probability at least 9/10.
Combining Lemmas 8.16 and 8.17, we get Theorem 8.15.
9 No degree queries
In this section, we show that the instance-non-optimality of bidirectional Dijkstra on directed graphs is mainly caused by degree queries (i.e., INDEG and OUTDEG for directed graphs, and DEG for undirected graphs). Specifically, we now assume that the only operation available to an algorithm is to take a previously seen vertex and request its next in- or out-neighbor, together with the weight of the corresponding edge. We refer to this as the no-degree model.
We retain the distinction between the order-dependent and order-oblivious models: in the former, the ordering is considered part of the input, whereas in the latter, it is not. Consequently, in the order-dependent model, an instance-smart algorithm may exploit the ordering by stopping its requests for subsequent in- or out-neighbors when the most important edges appear near the beginning of an adjacency list. In contrast, in the order-oblivious model, an instance-smart algorithm can only treat the order in which incident edges are returned as uniformly random.
In the no-degree model, we show that bidirectional Dijkstra is instance-optimal in almost all settings, regardless of whether the graph is directed or undirected and whether the model is order-dependent or order-oblivious. The only exception is the order-dependent setting on directed graphs, where bidirectional Dijkstra remains instance-non-optimal.
9.1 Order-Oblivious Instance-Optimality for Directed Graphs
We now use the following construction of , which does not preserve degrees.
Theorem 9.1. In the order-oblivious no-degree model, Algorithm 2 is instance-optimal on directed graphs.
Proof. Assume for contradiction that edges, where we recall from Equation (8) that denotes the expected number of vertices and edges visited by . We also recall from Section 2.5 that we use and to denote the sets of edges visited by the forward and backward searches, respectively, in the bidirectional Dijkstra's algorithm shown in Algorithm 2. By Lemma 2.2, , and the number of queries performed by bidirectional Dijkstra is . Then there exists a 1/20-bad edge and a 1/20-bad edge .
If exists in , then, by Lemma 3.2, is 1/5-bad, since has a 1/20-bad outgoing edge and has a 1/20-bad incoming edge . We can then apply Construction (a) to construct . Specifically, we construct by changing the edge weight so that . This is possible by Lemma 2.3, which shows that for and . Consequently, . Since the edge weight is the only difference between and , and is 1/5-bad, i.e., it is visited by with probability at most 1/5, can distinguish from with probability at most 1/5. This contradicts the assumption that is a good algorithm that outputs the correct answer on every instance with probability at least 9/10.
Now suppose that does not exist in . We construct by adding and setting . Specifically, we insert at a uniformly random position in the out-adjacency list of . Analogously, we insert at a uniformly random position in the in-adjacency list of . Recall that, in the order-oblivious model, the order in which the graph oracle returns edges in an adjacency list is considered uniformly random. In particular, appears after in the out-adjacency list of with probability . Since is -bad, it is visited by with probability at most . Analogously, is visited by with probability at most . Thus, the probability that either of the two edges is visited is at most . So that all three edges remain unvisited with probability at least .
Since degree queries are not available, on this event, A has not visited all edges in the out-adjacency list of or the in-adjacency list of , and therefore cannot detect the change in the out-degree of and in-degree of . As a result, A cannot distinguish G from with probability at least 1/5, contradicting the assumption that A is a good algorithm.
9.2 Order-Dependent Instance-Non-Optimality for Directed Graphs
We now show that disallowing degree queries does not eliminate instance-non-optimality in the order-dependent model on directed graphs.
Theorem 9.2. In the order-dependent no-degree model, the instance-optimality ratio of every algorithm is on directed graphs.
Proof. The claim is trivial if , so assume the opposite. Take the construction of Theorem 5.2 but give every vertex in an edge to every vertex in . Set , , and , so that the number of vertices is and the maximum in- and out-degree is . In particular, we place the edges between and at the beginning of the out-adjacency list of every vertex in and the in-adjacency list of every vertex in .
An instance-smart algorithm can first visit all edges incident to s. From this, it can identify the set as the set of neighbors of s with no out-edges, and identify as the others. Similarly, it can visit all in-neighbors of t, to identify the set as those with no in-edges, and identify as the others. It can also identify as an induced path by walking along out-edges starting from t. It has now counted all n vertices, and certified that no path from s to t visits and .
Note that we now consider the order-dependent model, in which the ordering is part of the input graph. In particular, the edges between and are placed at the beginning of the out-adjacency list of every vertex in . Hence, an instance-smart algorithm can inspect only the edges from to , without visiting or , by terminating the neighbor queries as soon as they start returning vertices in . As a result, the instance-smart algorithm requires only queries to inspect all edges from to . Since every path must go from to , then to , and finally to , the algorithm can then determine the shortest-path distance.
In contrast, consider any good algorithm. The algorithm must query every edge from to to ensure the correctly calculate the shortest -t path. Recall that an algorithm that aims to be instance-optimal must treat the ordering of the incident edges it receives as uniformly random, rather than relying on an instance-specific ordering. Consequently, on this graph, such an algorithm requires queries. Comparing this with the queries required by the instance-smart algorithm yields an instance-optimality ratio of .
9.3 Order-Dependent Instance-Optimality for Undirected Graphs
Theorem 9.3. In the order-dependent no-degree model, Algorithm 2 is instance-optimal on undirected graphs.
Proof. Let and denote the sets of vertices in and , respectively, that are incident to a 1/20-bad edge. Assume without loss of generality that .
Assume, for contradiction, that , where we recall from Equation (8) that denotes the expected number of vertices and edges visited by . Then there exists a 1/20-bad edge and a 1/20-bad edge .
If , or if is a 1/20-bad edge in G, then we can simply apply Construction (a) to construct .
If and does not exist in , we construct by adding and setting . This is possible by Lemma 2.3, which shows that for and . Consequently, .
Recall that we are now considering the order-dependent model, in which the ordering of edges within each adjacency list is part of the input. We place the newly added edge at the “bottom” of the adjacency lists of and , in the sense that the probability that reaches when scanning either adjacency list is no larger than the probability of reaching any existing edge in that list. Since and are both 1/20-bad, i.e., each is visited by with probability at most 1/20, the new edge is visited through the adjacency list of either or with probability at most 1/20, and hence is visited with probability at most 1/10 in total.
Moreover, degree queries are not available. Therefore, unless A scans an entire adjacency list, it cannot detect the change in the degree of or caused by adding . It follows that A can distinguish G from only if it visits , , or the newly added edge . By a union bound, this occurs with probability at most . Thus, A cannot distinguish G from with sufficiently high probability, contradicting the assumption that A is a good algorithm.
It is worth noting that this is precisely where the argument fails to extend to the order-dependent no-degree model on directed graphs. In the directed setting, the bad edge belongs to the in-adjacency list of , whereas the new edge must be inserted into the out-adjacency list of . For example, may have out-degree zero, in which case there is no bad edge in its out-adjacency list that can be used to hide the newly added edge . Thus, even without degree queries, adding may be detectable by A.
It therefore remains only to consider the case where exists in and is 1/20-good. In fact, this implies that, for every 1/20-bad edge with and every , there exists a 1/20-good edge . Hence, is incident to at least 1/20-good edges, which is at least the number of 1/20-bad edges between and .
Let denote the number of 1/20-good edges in , and let and denote the numbers of distinct 1/20-good and 1/20-bad undirected edges in , respectively. Summing over all such vertices , we obtain , where the factor 2 accounts for the fact that each 1/20-good edge may be counted from both endpoints. Clearly, . Moreover, each undirected edge occurs at most twice in . Therefore, .
Since every 1/20-good edge is visited by A with probability at least 1/20, A queries at least edges in expectation, contradicting the assumption that .
10 Zero-Weight Graphs and Unit-Weight Graphs
Throughout the paper, we consider only graphs with positive edge weights. In this section, we briefly discuss the cases where zero-weight edges are allowed, or the input graph is promised to have a smallest valid positive edge weight (e.g., an unweighted graphs).
We note that also establishes the instance-non-optimality of bidirectional Dijkstra on zero-weight and unweighted graphs, under the assumption that parallel edges are allowed. They obtain lower bounds of and on the instance-optimality ratio for zero-weight and unweighted graphs, respectively. Both lower bounds are established in the order-dependent model, allowing an instance-smart algorithm to be told the correct path. To get an order-oblivious result, the footnote of , Section 5.1] suggests coding the identifier of a vertex by giving it a neighbor who is a star whose degree is the identifier. Here we do not allow degree queries, and we only use constant degrees.
Theorem 10.1. When zero-weight edges are allowed, the instance-optimality ratio of every algorithm is in the order-oblivious no-degree model, for both directed and undirected graphs.
Proof. Consider the graph G illustrated in Figure 5. The graph contains two tree structures rooted at s and t, respectively. We first describe the tree rooted at s.
Starting from a complete binary tree, we use vertex degrees to encode every root-to-leaf path. For each pair of sibling vertices, we attach an additional leaf to exactly one of them (see the orange edges in Figure 5), so that the two siblings have distinct degrees. This degree distinction indicates which of the two siblings lies on the encoded path. For each leaf of the original binary tree, we further add a new adjacent vertex and attach additional leaves to this new vertex so that it has out-degree d (see the green edges in Figure 5). Consequently, a path from the root to any out-degree-d vertex at the bottom level can be uniquely specified by the sequence of degrees encountered along the path.
Let denote an arbitrary out-degree-d vertex at the bottom level of the tree rooted at s. The tree rooted at t is constructed symmetrically: we choose an arbitrary in-degree-d vertex at the bottom level. We assign weight 0 to every edge in the graph. All other leaf vertices in the tree rooted at s are disconnected from the tree rooted at t. Finally, we connect and by a zero-weight edge.
An instance-smart algorithm can “know” the degree sequence corresponding to the unique zero-length path and therefore follow it directly. It thus requires only queries to identify the zero-length path: queries suffice to navigate from to and from to by following the degree-encoded paths, while an additional queries suffice to identify the zero-weight edge between and by querying their neighbors.

Figure 5: Lower-bound construction for graphs with zero or unit weights.
In contrast, for an algorithm that aims to be instance-optimal over all instances, knowing the path code corresponding to one particular instance provides no useful information for other instances. Such an algorithm must therefore explore the whole graph to identify the zero-length path, resulting in query time. This yields an instance-optimality ratio of .
The above construction is described in the context of directed graphs, but it extends straightforwardly to undirected graphs by replacing every directed edge with an undirected edge. The instance-smart algorithm can still navigate from s to and from t to by following the degree-encoded paths. The only difference is that, since the edges are now undirected, at each vertex the algorithm excludes the edge leading back to its parent and uses the degrees of the remaining neighbors to determine which vertex to visit next.
Theorem 10.2. On unweighted graphs (or positively weighted graphs with a smallest valid positive weight), the instance-optimality ratio of every algorithm is in the order-oblivious no-degree model, for both directed and undirected graphs.
Proof. Let denote the smallest valid positive edge weight, or the unit weight, say 1, if we restrict our attention to unweighted graphs. We consider the same graph as illustrated in Figure 5, but set the weight of every edge to and replace each degree-d vertex at the bottom level with a degree- vertex. There is a unique s-t path P that passes through the edge . All other leaf vertices in the tree rooted at s are disconnected from the tree rooted at t.
An instance-smart algorithm can still “know” the path code corresponding to P and follow it directly. However, it must additionally verify that no missing part of the tree structure could give rise to a shorter path. After inspecting all vertices in the tree rooted at s at or above the level containing , as well as all vertices in the tree rooted at t at or above the level containing , the algorithm can certify that no shorter path exists. Indeed, since all edge weights are the smallest valid positive edge weight , even if there were an edge connecting the two trees at the levels containing and , the resulting path could not be shorter than P. Thus, the instance-smart algorithm requires only queries.
In contrast, an algorithm that aims to be instance-optimal over all instances cannot directly identify the unique path . It must instead scan the edges to locate , requiring queries in expectation. This yields an instance-optimality ratio lower bound of .
References
[ABC17] Peyman Afshani, Jérémy Barbay, and Timothy M. Chan. Instance-optimal geometric algorithms. J. ACM, 64(1):3:1–3:38, 2017. doi:10.1145/3046673.
[Bar13] Albert-László Barabási. Network science. Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences, 371(1987):20120375, 03 2013. arXiv:https://royalsocietypublishing.org/rsta/article-pdf/doi/10.1098/rsta.2012.0375/414334/rsta.2012.0375.pdf, doi:10.1098/rsta.2012.0375.
[BCW25] Guy Blanc, Clément L. Canonne, and Erik Waingarten. Instance-optimal uniformity testing and tracking. In 66th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2025, Sydney, Australia, December 14-17, 2025, pages 1351–1365. IEEE, 2025. doi:10.1109/FOCS63196.2025.00071.
[CL16] Lijie Chen and Jian Li. Open problem: Best arm identification: Almost instance-wise optimality and the gap entropy conjecture. In Vitaly Feldman, Alexander Rakhlin, and Ohad Shamir, editors, Proceedings of the 29th Conference on Learning Theory, COLT 2016, New York, USA, June 23-26, 2016, JMLR Workshop and Conference Proceedings, pages 1643–1646. JMLR.org, 2016. URL: http://proceedings.mlr.press/v49/chen16b.html.
[Dan63] George Bernard Dantzig. Linear Programming and Extensions. RAND Corporation, Santa Monica, CA, 1963. doi:10.7249/R366.
[dBvR 25] Sarita de Berg, Ivor van der Hoog, Eva Rotenberg, Daniel Rutschmann, and Sampson Wong. Instance-optimal imprecise convex hull. In Anne Benoit, Haim Kaplan, Sebastian Wild, and Grzegorz Herman, editors, 33rd Annual European Symposium on Algorithms, ESA 2025, Warsaw, Poland, September 15-17, 2025, volume 351 of LIPIcs, pages 25:1–25:15. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2025. URL: https://doi.org/10.4230/LIPIcs.ESA.2025.25, doi:10.4230/LIPICS.ESA.2025.25.
[DGST88] James R. Driscoll, Harold N. Gabow, Ruth Shrairman, and Robert Endre Tarjan. Relaxed heaps: An alternative to fibonacci heaps with applications to parallel computation. Commun. ACM, 31(11):1343–1354, 1988. doi:10.1145/50087.50096.
[Dij59] Edsger W. Dijkstra. A note on two problems in connexion with graphs. Numerische Mathematik, 1:269–271, 1959. doi:10.1007/BF01386390.
[DKLR00] Paul Dagum, Richard M. Karp, Michael Luby, and Sheldon M. Ross. An optimal algorithm for monte carlo estimation. SIAM J. Comput., 29(5):1484–1496, 2000. doi:10.1137/S0097539797315306.
[DLSV23] Trung Dang, Jasper C.H. Lee, Maoyuan Song, and Paul Valiant. Optimality in mean estimation: beyond worst-case, beyond sub-gaussian, and beyond moments.
In Proceedings of the 37th International Conference on Neural Information Processing Systems, NIPS '23, Red Hook, NY, USA, 2023. Curran Associates Inc.
[Dre69] Stuart E. Dreyfus. An appraisal of some shortest-path algorithms. Oper. Res., 17(3):395–412, 1969. URL: https://doi.org/10.1287/opre.17.3.395, doi:10.1287/OPRE.17.3.395.
[FLN03] Ronald Fagin, Amnon Lotem, and Moni Naor. Optimal aggregation algorithms for middleware. J. Comput. Syst. Sci., 66(4):614–656, 2003. doi:10.1016/S0022-0000(03)00026-6.
[FT87] Michael L. Fredman and Robert Endre Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM, 34(3):596–615, 1987. doi:10.1145/28869.28874.
[HHR 24] Bernhard Haeupler, Richard Hladík, Václav Rozhon, Robert E. Tarjan, and Jakub Tetek. Universal optimality of dijkstra via beyond-worst-case heaps. In 65th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2024, Chicago, IL, USA, October 27-30, 2024, pages 2099–2130. IEEE, 2024. doi:10.1109/FOCS61266.2024.00125.
[HHR 25] Bernhard Haeupler, Richard Hladík, Václav Rozhon, Robert E. Tarjan, and Jakub Tetek. Bidirectional dijkstra's algorithm is instance-optimal. In Ioana Oriana Bercea and Rasmus Pagh, editors, 2025 Symposium on Simplicity in Algorithms, SOSA 2025, New Orleans, LA, USA, January 13-15, 2025, pages 202–215. SIAM, 2025. doi:10.1137/1.9781611978315.16.
[HNR68] Peter E Hart, Nils J Nilsson, and Bertram Raphael. A formal basis for the heuristic determination of minimum cost paths. IEEE transactions on Systems Science and Cybernetics, 4(2):100–107, 1968.
[LRN 22] Zhaoqi Li, Lillian J. Ratliff, Houssam Nassif, Kevin Jamieson, and Lalit Jain. Instance-optimal PAC algorithms for contextual bandits. In Sanmi Koyejo, S. Mohamed, A. Agarwal, Danielle Belgrave, K. Cho, and A. Oh, editors, Advances in Neural Information Processing Systems 35: Annual Conference on Neural Information Processing Systems 2022, NeurIPS 2022, New Orleans, LA, USA, November 28 - December 9, 2022, 2022. URL: http://papers.nips.cc/paper_files/paper/2022/hash/f4821075019a058700f6e6738eea1365-Abstract-Conference.html.
[MV22] Michael Mitzenmacher and Sergei Vassilvitskii. Algorithms with predictions. Commun. ACM, 65(7):33–35, 2022. doi:10.1145/3528087.
[Nic66] T. A. J. Nicholson. Finding the shortest route between two points in a network. Comput. J., 9(3):275–280, 1966. URL: https://doi.org/10.1093/comjnl/9.3.275, doi:10.1093/COMJNL/9.3.275.
[NRTT24] Shyam Narayanan, Václav Rozhon, Jakub Tetek, and Mikkel Thorup. Instance-optimality in i/o-efficient sampling and sequential estimation. In 65th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2024, Chicago, IL, USA, October 27-30, 2024, pages 658–688. IEEE, 2024. doi:10.1109/FOCS61266.2024.00048.
[Poh69] Ira Pohl. Bi-directional and heuristic search in path problems. PhD thesis, Stanford University, USA, 1969. URL: https://searchworks.stanford.edu/view/2197829.
[Rou19] Tim Roughgarden. Beyond worst-case analysis. Commun. ACM, 62(3):88–96, 2019. doi:10.1145/3232535.
[TW25] Mikkel Thorup and Hanzhi Wang. Instance optimality in pagerank centrality estimation. CoRR, abs/2512.16087, 2025. URL: https://doi.org/10.48550/arXiv.2512.16087, arXiv:2512.16087, doi:10.48550/ARXIV.2512.16087.
[VV16] Gregory Valiant and Paul Valiant. Instance optimal learning of discrete distributions. In Daniel Wichs and Yishay Mansour, editors, Proceedings of the 48th Annual ACM SIGACT Symposium on Theory of Computing, STOC 2016, Cambridge, MA, USA, June 18-21, 2016, pages 142–155. ACM, 2016. doi:10.1145/2897518.2897641.
[VV17] Gregory Valiant and Paul Valiant. An automatic inequality prover and instance optimal identity testing. SIAM J. Comput., 46(1):429–455, 2017. doi:10.1137/151002526.
[VV20] Gregory Valiant and Paul Valiant. Instance optimal distribution testing and learning. In Tim Roughgarden, editor, Beyond the Worst-Case Analysis of Algorithms, pages 506–526. Cambridge University Press, 2020. doi:10.1017/9781108637435.029.