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

Matt J
Matt J 2012년 10월 29일
편집: Matt J 2012년 10월 29일
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 2012년 10월 29일
If there are any cycles then the longest path is infinite.

댓글을 달려면 로그인하십시오.

답변 (2개)

Massimo Zanetti
Massimo Zanetti 2016년 10월 9일

3 개 추천

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 2017년 12월 14일

1 개 추천

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

MICHAEL MONT-ETON
MICHAEL MONT-ETON 2020년 11월 29일
Ivan, Thanks for the tip. It is useful for finding collection of independent paths.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Networks에 대해 자세히 알아보기

제품

질문:

2012년 10월 29일

댓글:

2020년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by