GraphTheory
ShortestAncestralPath
determine shortest ancestral path in digraph
ShortestDescendantPath
determine shortest descendant path in digraph
Calling Sequence
Parameters
Options
Description
Definition
Examples
Compatibility
ShortestAncestralPath(G, u, v, opts)
ShortestAncestralPath(G, C, opts)
ShortestDescendantPath(G, u, v, opts)
ShortestDescendantPath(G, C, opts)
G
-
graph
u, v
vertices of the graph
C
list or set of vertices of the graph
opts
(optional) one or more options as specified below
avoidvertices=list or set
Specifies vertices to avoid in building a path.
If vertices are specified here, the resulting path may not be shortest in G.
distance=truefalse
Specifies whether to return the distance along with the shortest path.
If true, each element of the list output of ShortestPath will be a two-element list, the first element of which is the path and the second of which is the weighted path distance to the common ancestor.
ignoreweights=truefalse
Specifies whether to ignore edge weights if present. The default is false.
ShortestAncestralPath(G,u,v) returns a shortest ancestral path of u and v in the directed graph G.
ShortestAncestralPath(G,C) returns a shortest ancestral path of the vertices C in the directed graph G.
ShortestDescendantPath(G,u,v) returns a shortest descendant path of u and v in the directed graph G.
ShortestDescendantPath(G,C) returns a shortest descendant path of the vertices C in the directed graph G.
A vertex u is a common ancestor of a set C of vertices of G if it is an ancestor of each vertex in C.
If G is a directed graph and u and v are vertices of G, an ancestral path of u and v is a pair (p,q) where p is a directed path from w to u, and q is a directed path from w to v, where w is an ancestor of both u and v.
A shortest ancestral path of u and v is an ancestral path of minimum length over all common ancestors, where the length is defined as the sum of the lengths of the two directed paths from a common ancestor to u and to v respectively.
A descendant path and shortest descendant path is defined analogously for descendants.
In this example, 1, 2, and 4 are all common ancestors of 5 and 6, but the shortest ancestral path is to vertex 4.
with⁡GraphTheory:
G≔GraphTheory:-Graph⁡6,1,2,2,3,2,5,3,4,3,6,4,5,4,6
G≔Graph 1: a directed graph with 6 vertices and 7 arcs
DrawGraph⁡G,style=tree
ShortestAncestralPath⁡G,5,6
4,5,4,6
We can however explicitly avoid paths through vertex 4, in which case a path through vertex 2 is chosen.
ShortestAncestralPath⁡G,5,6,avoidvertices=4
2,5,2,3,6
The GraphTheory[ShortestAncestralPath] and GraphTheory[ShortestDescendantPath] commands were introduced in Maple 2025.
For more information on Maple 2025 changes, see Updates in Maple 2025.
See Also
Ancestors
LowestCommonAncestors
MinimalSpanningTree
SpanningTree
Download Help Document