3

I am aware of using Bellman-Ford on a graph $G=(V,E)$ with no negative cycles to find the single-source single-destination shortest paths from source $s$ to target $t$ (both in $V$) using at most $k$ edges. Assuming we have no negative edge weights at all, can we use Dijkstra's algorithm for the same?

My thoughts/algorithm: I was wondering if instead of having a $dist[u$] array (storing the best known distance from s to u), we could use a $dist[u][k]$ table to store the best known distance from $s$ to $u$ using at most $k$ edges (dynamic programming maybe?), and similarly have the priority queue with $(u,n)$ tuples as keys. We can then terminate the algorithm when the tuple popped off the priority queue is $(t,n)$ where t is the target destination and $n <= k$?

Raphael
  • 72,336
  • 29
  • 179
  • 389
Mathguy
  • 411
  • 5
  • 14
  • 1
    As far as I remember you can use Dijkstra's algorithm instead of Bellman-Ford when you don't have edges with negative distance in you graph; I'd have to take a closer look at both the algorithms to elaborate more though – mewa Feb 16 '16 at 13:04
  • 1
  • Does the graph have any edges with negative length? 2. What time complexity are you looking for? What's the fastest algorithm you were able to come up with? There's a standard solution based on "the product construction" that increases the running time by a factor of $k$; is that of interest to you?
  • – D.W. Feb 17 '16 at 03:20
  • See also http://cs.stackexchange.com/a/43099/755 for a loosely related but not identical problem. – D.W. Feb 17 '16 at 03:24
  • @D.W. thanks for the response! 1. No, only >= 0 edge weights. 2. The time complexity I'm looking for is $O(k(V+E)log(V))$ and that's the complexity of my algorithm too, but I'm not sure if it's right. Also, please could you link me to the 'product construction' solution? – Mathguy Feb 17 '16 at 06:18
  • OK. Please edit the question to include this information, and also present your algorithm. We want questions to be self-contained, so people don't need to read the comments to understand the question. – D.W. Feb 17 '16 at 06:23
  • 1
    I edited to remove a potential confusing point for readers: Bellman-Ford only requires that the graph have no negative cycles; you want to assume more. – Raphael Feb 17 '16 at 07:20
  • 1
    Note that your target running time, assuming the bound is tight, is worse than Bellman-Ford, which runs in time $O(|V| + k \cdot |E|)$ here. – Raphael Feb 17 '16 at 07:25
  • https://cs.stackexchange.com/q/118977/755 – D.W. Jan 19 '20 at 19:31