Would Dijkstra's algorithm work in this case? [duplicate] - dijkstra

This question already has answers here:
How do I find the shortest path that covers all nodes in a directed cyclic graph?
(4 answers)
Closed 3 years ago.
Usually, Dijkstra's algorithm finds out the shortest distance to get from one node to another.
But can it work out the shortest distance to get from one node to another by going through every other single node. I need it to go to every other node before reaching the end node.
How would I apply this using Dijkstra's algorithm for an undirected graph, or is it not possible?

The problem described is a variation of the Travelling salesman problem (TSP). This problem is NP-hard. A brute force solution has time complexity of O(n!). Using dynamic programming, you can achieve a time complexity of O(n2 2n). There are various heuristics to achieve a near optimal solution in polynomial time.
Dijsktra's algorithm will pick the shortest path to each new node found which may not be the optimal solution for the travelling salesman problem. As counter example, consider a graph connecting nodes with very short paths to each node except the end node. Imagine the shortest path from the 2nd last node to the end node to be exceptionally large such that it is optimal to take an intermediate non-shortest path between intermediate nodes so as to reach the end node.

Related

Can we add a turning penalty in Dijkstra's algorithm

I am trying to code Dijkstra algorithm to find the shortest paths between nodes of some electrical cable trays (given as directed graph). My question is; if we have turns (i.e. not a straight path as the company wish to have) how we can handle this problem ?
Dijkstra cannot incorporate a turn-penalty directly, since it is built around the assumption that the cost to reach a node is independent of its "context".
It is possible to rewrite your graph so that every turn is associated with taking an edge, so turn costs become normal costs. Dijkstra can then be applied to that graph. A full explanation can be found in "Modeling Costs of Turns in Route Planning" (Stephan Winter). The graph used for this (line graph) is sometimes called the dual graph, though that term traditionally had a different meaning. Roughly, you introduce a node for every original edge, and an edge between two of the new nodes if the corresponding edges are both adjacent to the same original node (every tiny path of 2 steps is represented by an edge in the new graph). All edges leading out of the source and into the target correspond to separate nodes in the new graph, to avoid turning the problem into multi-source/multi-target shortest path, you may add an additional source node and target node that "tie the edges together" (with zero cost).

How to improve Dijkstra algorithm for single source single-target shortest path?

what improvement can be made in given image dijkstra algorithm to improve Dijkstra algorithm for single source single-target shortest path?
https://i.stack.imgur.com/H5ZW6.png
Improvement can be made in this way:
when you visit a node again and no node weight is updating. then one can say there is no need traverse all the node. you can stop the traversing before visiting all the nodes in loop.

Branch and Bound approach to the edit distance algorithm

I am trying to implement Branch and Bound approach to the edit distance algorithm. I can't find any hints over internet to start with. Can anyone help me to get into the track of the algorithm.
My apologies for posting this as an answer, I wanted to add it as just a comment, but I don't have sufficient reputation to add comments.
Try to approach your literature search of this subject rather in the context of the graph similarity problem than for the edit distance algorithm; the prior is a more general and well-studied problem which the problem of finding the minimum edit distance fall under. The strings in any instance of your edit distance problem can be described as simple directional graphs, and the operations of insertion/deletion and substitution in the edit distance algorithm has similar operations in the graph similarity problem (e.g., insertion of vertices and edges/deletion of vertices and edges/changing labels on edges and so on).

find the Shortest Path between all the vertices in a graph without giving start or end points

i know about the traveling salesman problem, but is there any other algorithm/problem which better fits my needs/description? I need to describe my problem with the help of such a mathematical description.
I have a set of nodes with known start- and endpoint. So i just need to calculate the shortest way to visit all the three points between that two. Dijkstra and similar algorithms try to find the shortest path between two points, so here they probably won´t visit all points between. Or is there a algorithm which finds shortest way and visit all points between two points?
You can achieve it using Ant colony optimization algorithms. Refer Ant colony optimization algorithms.
The complexity of the general case of your problem is at least as high as for the Travelling Salesman problem. Just imagine the case where your two endpoints are basically in the same position, then your problem becomes equivalent to the Travelling Salesman.
If you never expect more than five points in your graph though, do you really need to bother with fancy algorithms? You could just do an exhaustive search for the best solution. Since the only decision is the order in which you visit the three points in the middle, you will only have to test 3! = 6 different paths. Even if I misunderstand you and you want the overall shortest open path that visits all nodes, that would still only be 5! = 120 different paths to test (60 if distances are the same in both directions).

Dijkstra's algorithm Vs Uniform Cost Search (Time comlexity)

My question is as follows: According to different sources, Dijkstra's algorithm is nothing but a variant of Uniform Cost Search. We know that Dijkstra's algorithm finds the shortest path between a source and all destinations ( single-source ). However, we can always modify Dijkstra to find the the shortest path between a START and a GOAL state ( when the goal is popped from the priority queue, we simply stop); but doing so, the worst case scenario will be still finding the shortest path from START to all other nodes ( suppose the goal is the furthest node in the graph).
If we implement Dijkstra's algorithm using a min-priority heap, the running time will be
O(V log V +E) , where E is the number of edges and V the number of vertices.
Since Uniform Cost Search is the same as Dijkstra ( slightly different implementation), then the running time of UCS should be similar to Dijkstra, right? However, according to my AI class, Uniform Cost Search is exponential at the worst case, and it takes O(b1 + [C*/ε]), where C* is the cost of the optimal solution. ( b is the branching factor)
How can both algorithms be the same while they have different running times? Is the running time the same, but the way we look at it is different?
I would appreciate your help :):) Thank you
Is the running time the same, but the way we look at it is different?
Yes. Uniform cost search can be used on infinitely large graphs, on which Dijkstra's original algorithm would never terminate. In such situations, it's no use defining complexity in terms of V and E as both might be infinite and the resulting big-O figure meaningless.