Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the longest path between two vertices in a directed acyclic graph
ResourceFunction["FindLongestPath"][g,s,t] finds the longest path from source vertex s to target vertex t in the directed acyclic graph g. | |
ResourceFunction["FindLongestPath"][{v→w,…},…] uses rules v→w to specify the graph g. |
Find the longest path from the root of a directed acyclic graph (DAG) to a leaf:
In[1]:= |
|
In[2]:= |
|
Out[2]= |
|
Highlight the longest path:
In[3]:= |
|
Out[3]= |
|
FindLongestPath works with directed acyclic graphs:
In[4]:= |
|
In[5]:= |
|
Out[5]= |
|
Use rules to specify the graph:
In[6]:= |
|
In[7]:= |
|
Out[7]= |
|
In[8]:= |
|
Out[8]= |
|
FindLongestPath is left unevaluated if the input graph is not a DAG:
In[9]:= |
|
Out[9]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License