0
$\begingroup$

I'm trying to practice some theory on graphs:

Namely, we have given connected undirected weighted graph with $N$ nodes and $M$ edges, let's say we want to find the shortest paths between node $1$ and node $N$. But, not only that we want to find all the paths with same shortest distance between $1$ and $N$.

Now I was wondering that if we have given $N = 300$ this number (of shortests paths) can be huge, my question is: is it possible to find all shortest paths in graph with at most 300 nodes in polynomial time.

$\endgroup$
  • 1
    $\begingroup$ If you limit the problem to $n \leq 300$, it can be solved in $O(1)$. If you don't limit $n$, there can be super-exponentially many shortest paths, so no. $\endgroup$ – Raphael Sep 3 '17 at 21:50
  • $\begingroup$ I want to solve only for $n \leq 300$, what is the algorithm for getting O(1) ? $\endgroup$ – someone12321 Sep 4 '17 at 7:15
  • $\begingroup$ Every algorithm is in O(1) for fixed n -- asymptotics are meaningless in such a scenario. For real-world performance, the complexity theory perspective is utterly useless. You need to analyze algorithms in more detail, probably also incorporating the particulars of your set of possible inputs (can the general worst cases happen? are they likely?). To be frank, if you didn't understand my earlier comment this is probably beyond you. Just try out different algorithms and see which work best for you. $\endgroup$ – Raphael Sep 4 '17 at 7:22