Find the longest path in a graph?

16 visualizzazioni (ultimi 30 giorni)
SOUMEN ATTA
SOUMEN ATTA il 29 Ott 2012
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 Commenti
Matt J
Matt J il 29 Ott 2012
Modificato: Matt J il 29 Ott 2012
Who is "we"? If you mean you and your classmates, show us your code and where in it you are stuck.
Walter Roberson
Walter Roberson il 29 Ott 2012
If there are any cycles then the longest path is infinite.

Accedi per commentare.

Risposte (2)

Massimo Zanetti
Massimo Zanetti il 9 Ott 2016
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
Ivan il 14 Dic 2017
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 Commento
MICHAEL MONT-ETON
MICHAEL MONT-ETON il 29 Nov 2020
Ivan, Thanks for the tip. It is useful for finding collection of independent paths.

Accedi per commentare.

Categorie

Scopri di più su Networks in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by