Optimal root in shortest path tree (SPT) - graph-algorithm

I would like to find the "optimal" shortest path tree (SPT) in some undirected weighted graph. As "optimal" SPT, I mean so its maximal path from root to leaf is minimal from any other potential SPTs.
It is quite easy to find SPT from 1 root via Dijkstra's algorithm. So I can run Dijkstra from all vertices and find the "optimal" SPT and its root.
Is there any faster algorithm?

Related

Can I use Breadth-First-Search on weighted graphs if I modify it?

I am having a discussion with a friend if the following will work:
We recently learned in a lecture about Breadth-First-Search. I know that it is a special case of Dijkstra where each edge weight is set to one. Assume now we are given a graph where the edges have integer weights of more than one. Then I would modify this graph by introducing additional vertices and connecting them by edges with weight one, e.g. assume we have an edge of weight 3 connecting the vertices u and v, then I would introduce dummy-vertices d1, d2, remove the edge connecting u and v and instead add edges {u, d1}, {d1, d2}, {d2,v} of weight one.
If I modify my whole graph this way and then apply breadth-first search starting from one of the original vertices, wouldn't this work as well?
Thank you very much in advance!
Since BFS is guaranteed to return an optimal path on unweighted graphs, and you've created the unweighted equivalent of your original graph, you'll be guaranteed to get the shortest path.
What you lose by doing this over Dijkstra's algorithm is runtime optimality. Now the runtime of your algorithm is dependent on the edge weights, whereas Dijkstra's is only dependent on the number of edges.
This sort of thought experiment is a great way to understand how Dijkstra's algorithm works (eg. how would you modify your algorithm to not require creating a new graph? Or not take 100 steps for an edge with weight 100?). In fact this is probably how Dijkstra discovered the algorithm to begin with.

neo4j cypher filter nodes apoc dijkstra

I have a graph, and i want to use the apoc dijkstra algorithm on it, so far everything is working. But i want to exclude certain nodes or node properties from the possible path, so that the dijkstra algorithm doesnt return a path that contains these excluded nodes or properties.
Is it possible, for example, to filter all existing nodes BEFORE calling the apoc.dijkstra algorithm?
I know that is it possible to filter the found path AFTER the algorithm, but then it is possible that there is a possible path in the graph that was not found, because the filterting of the nodes occurred afterwards..
Apoc dijkstra is an old an deprecated implementation of Dijkstra algorithm. You should check out the Graph Data Science plugin at https://neo4j.com/docs/graph-data-science/current/. It supports shortest weighted path algorithm or otherwise known as dijkstra algorithm, https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/shortest-path/. You can can define which nodes you want and relationships you want to traverse when projecting the graph.
Hope this helps!

Longest non repetitive path in a graph?

I was working on to find the shortest path between two nodes in undirected acyclic graph using Dijkstra's algorithms. I wanted to find the longest path that is possible by the same algorithm. I also want to avoid few routes with 0 edge values. How do I do that using Dijkstra's algorithm?
Now after searching through Stackoverflow I came across one given solution which just states that we need to modify the relaxation part to find the longest path.
Like:
if(distanceValueOfNodeA< EdgeValueofNodeBtoA )
{
distanceValueOfNodeA = EdgeValueofNodeBtoA;
}
But we are not considering adding distanceValueOfNodeB
But for shortest paths we calculate:
distanceValueOfNodeA = distanceValueOfNodeB+EdgeValueofNodeBtoA
Should we ignore distanceValueOfNodeB to calculate distanceValueOfNodeA ?
I am sorry to disappoint you but that problem is known as Longest path in a graph and there isn't an efficient algorithm to solve it, so niether Djikstra algorithm with any modification can.
It belongs to a class of problems known as NP-hard,those are problems for which there isn't (at the moment) an algorithm to solve them in faster time complexity compared to exponential.

How to minimize the maximum cost of a path in a vertex disjoint path cover?

Given a directed weighted graph G and n, where n is the number of paths to be used to cover all the vertices in the graph G. How can I minimize the maximum cost of the longest path? (assuming that a solution always exist in this graph)
For n = 1, this obviously becomes a Travelling Salesman Problem - which is NP-hard. Thus, I wouldn't look for exact algorithms in your case.
My guess would be that a good solution for small n would be to use one of the abundant algorithms for the Travelling Salesman Problem (which usually approximate optimal solutions quite good) and then remove the (n-1) heaviest edges from the found path. That way you end with n paths.
The Wikipedia Article on TSP actually lists some pretty easy algorithmic techniques which should give you a reasonably good approximation.

Shortest positive path in a directed acyclic graph

We are given a directed acyclic graph with arbitrary weights on edges and two specific nodes, s and t, where in-degree of s and out-degree of t is 0. How to determine the shortest path from s to t that has positive cost?
Use a modified Bellman-Ford, which removes edges from the graph if a resulting shortest path cost is <0 until you reach a cost, that is not <0.

Resources