does anyone know the algorithm for finding k-shortest path, I searched on Internet and found Yen's but it's so complex ?
Thanks so much.
does anyone know the algorithm for finding k-shortest path, I searched on Internet and found Yen's but it's so complex ?
Thanks so much.
It cannot be done efficiently (polynomially)1 - the problem is NP-Hard
Think of it this way - is you could find even the length of a k shortest path (asssume simple path here) polynomially, by doing a binary search on the range [1,n!]
for k
, you could find if there is a hamiltonian path in the graph (by finding a path of length n
).
Since the hamiltonian path problem is NP-Hard, so does this problem, and there is no known polynomial solution to it.
(1)probably, unless P=NP, but most CS researchers believe it is very unlikely
This is solved with dis-joint set. Google it but in short you have 2 vectors. one for parents initialized with -1. the other for rank initialized with zero's. Now start at the source node. you go for each possible node you can get from there. add them to your set by making their parent[i] = current node. the decision which one will be the parent of who is done based on the rank[i] which holds the number