Find the longest path in a graph?
Ältere Kommentare anzeigen
Adjacency matrix of graph is given to us. Now we need to find out the longest path between two nodes. Input: Adjacency matrix of the graph, source node and destination node. Output: Longest path between source node and destination node.
2 Kommentare
Walter Roberson
am 29 Okt. 2012
If there are any cycles then the longest path is infinite.
Antworten (2)
Massimo Zanetti
am 9 Okt. 2016
3 Stimmen
Generally this is NP-hard problem. However, for DAGs (directed acyclic graphs) there is one clever way to solve the problem. It is called "topological sorting". See details here or elsewhere in google: https://en.wikipedia.org/wiki/Topological_sorting
Ivan
am 14 Dez. 2017
1 Stimme
Try to invert signs of weight coefficient and calculate shortest path with built-in shortestpath function. It will be the longest path for initial weights.
1 Kommentar
MICHAEL MONT-ETON
am 29 Nov. 2020
Ivan, Thanks for the tip. It is useful for finding collection of independent paths.
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!