Find the longest path in a graph?

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 comentarios

Matt J
Matt J el 29 de Oct. de 2012
Editada: Matt J el 29 de Oct. de 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 el 29 de Oct. de 2012
If there are any cycles then the longest path is infinite.

Iniciar sesión para comentar.

Respuestas (2)

Massimo Zanetti
Massimo Zanetti el 9 de Oct. de 2016

3 votos

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 el 14 de Dic. de 2017

1 voto

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 comentario

MICHAEL MONT-ETON
MICHAEL MONT-ETON el 29 de Nov. de 2020
Ivan, Thanks for the tip. It is useful for finding collection of independent paths.

Iniciar sesión para comentar.

Categorías

Más información sobre Networks en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 29 de Oct. de 2012

Comentada:

el 29 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by