longest path in undirected vs directed graph - algorithm

I need to solve a longest path problem for graphs that are both directed and non-directed (unweighted in both cases).
For directed graph, it is pretty easy to find dynamic programming algorithms that are able to solve the problem in pseudopolynomial time, starting at some node, and calculating the longest path for subproblems until every problem has been looked at.
Can I do a similar thing for at non-directed graph? I cant seem to find any litterature about it?

Every directed graph algorithm works on undirected graphs. Simply treat each edge as two directed edges with the same weight.

Related

Which algorithm is helpful in finding shortest path from source to sink in a graph that has all negative edges(cost)?

I'm wanting to find the shortest path from source to sink in a directed graph, that has all negative weights(edges). From the algorithms that I'm aware of I don't think of any algorithm that helps solve problem like this. Dijkstras algorithm fails for graphs with negative edge! and also I don't want to traverse through all nodes.
There are no negative cycles.

Non-directed graph algorithm to find lowest cost path

I know a few algorithms that are able to find the lowest cost path for directed graph (just as Dijkstra and Floyd).
Is there any algorithm that works for non-directed graphs?
My problem is: I need to find the lowest cost path from a to b passing through all vertexes (undirected graph).
My problem is: I need to find the lowest cost path from a to b passing
through all vertexes (non-oriented graph)
This is the Traveling Salesman Problem, which is NP-Hard, so there is no known efficient solution to it.
However, if the graph is fairly small, there are some techniques to solve it optimally (in exponential time), like Dynamic Programming.
In general, changing an undirected graph to a directed one is fairly easy and is done by changing an undirected edge {u,v} to two directed edges (u,v) and (v,u)
Provided you have nonnegative edge values, you could consider every edge in an undirected graph as two edges in a directed graph, one pointed to and from connected vertices. Then you could use one of many algorithms including the ones you listed.

Finding shortest path in non-weighted graphs

During a course in University concerning graph theory, we were talking about finding shortest paths thus Dijkstra's algorithm came up, at that point I should mention that the edges of the graph were weighted, with weights>0. Then the professor asked how we could find the shortest path if the edges weren't weighted, I thought the same algorithm would do, since the edges had the "same" non-negative weight. But he suggested BFS. Is this true? wouldn't Dijkstra work correct? I'm not questing BFS finding the path but since it is exhaustive I thought maybe it would be better to avoid it.
Dijsktra worked fine for me even with non-wighted graphs. Every connection just has weight 1.

What is the difference between Travelling Salesman and finding Shortest Path?

The only difference I could think of for the question is that in the Travelling Salesman Problem (TSP) I need to find a
minimum permutation of all the vertices in the graph and in Shortest Paths problem there is no need to consider all the vertices we can search the states space for minimum path length routes can anyone suggest more differences.
You've already called out the essential difference: the TSP is to find a path that contains a permutation of every node in the graph, while in the shortest path problem, any given shortest path may, and often does, contain a proper subset of the nodes in the graph.
Other differences include:
The TSP solution requires its answer to be a cycle.
The TSP solution will necessarily repeat a node in its path, while a shortest path will not (unless one is looking for shortest path from a node to itself).
TSP is an NP-complete problem and shortest path is known polynomial-time.
If you are looking for a precise statement of the difference I would say you just need to replace your idea of the "permuation" with the more technical and precise term "simple cycle visiting every node in the graph", or better, "Hamilton cycle":
The TSP requires one to find the simple cycle covering every node in the graph with the smallest weight (alternatively, the Hamilton cycle with the least weight). The Shortest Path problem requires one to find the path between two given nodes with the smallest weight. Shortest paths need not be Hamiltonian, nor do they need to be cycles.
With the shortest path problem you consider paths between two nodes. With the TSP you consider paths between all node. This makes the latter much more difficult.
Consider two paths between nodes A and B. One over D the other one of C. Let the one over C be the longer path. In the Shortest Path problem this path can get immediately discarded. In the TSP it is perfectly possible that this path is part of the over all solution, because you'll have to visit C and visiting it later might be even more expensive.
Therefor you can't break down the TSP in similar but smaller sub-problems.
Shortest path is just have source and target.we need to find shortest path between them obviously output must be tree in polynomial-time.
Finding Shortest Path:-
Undirected graphs:
Dijkstra's algorithm with list O(V^2)
Directed graphs with arbitrary weights without negative cycles:
Bellman–Ford algorithm Time complexity O(VE)
Floyd–Warshall's Algorithm is used to find the shortest paths between between all pairs
TSP (Travelling-Salesman Problem) is not like that we have cover every node from source and finally we've reach source at minimum cost.Eventually there must be cycle. TSP is an NP-complete problem
Ref:
https://en.wikipedia.org/wiki/Shortest_path_problem
https://en.wikipedia.org/wiki/Travelling_salesman_problem
http://www.geeksforgeeks.org/travelling-salesman-problem-set-1/
http://www.geeksforgeeks.org/greedy-algorithms-set-6-dijkstras-shortest-path-algorithm/
https://www.hackerearth.com/practice/algorithms/graphs/shortest-path-algorithms/tutorial/
In TSP, you need to both visit all nodes and also return to your starting point. This complicates the problem immensely.

An algorithmic question concerning shortest paths and such

I have a very, very large graph, and I want to find the shortest path from one vertex to another. The graph is directed and unweighted.
I have considered using some modification of Dijkstra's algorithm, but I usually use that for weighted undirected graphs.
So then my other thought was to use a DFS, since I can treat all the weights as one.
Any suggestions? a
EDIT: Ok, I meant to say BFS, I'm sorry.
Try a BFS instead.
(Note that Dijkstra's algorithm works perfectly fine for unweighted directed graphs — it just happens that in the unweighted case, doing it smartly is essentially equivalent to a breadth-first search.)
Have you tried using A*?

Resources