This class provides diverse algorithms and services for tree-structured graphs or subgraphs.
Remarks
Note: Methods of this class work with instances of Graph. To analyze IGraph instances that are directed trees use TreeAnalyzer instead.
Definitions
- Tree: An acyclic graph, in which any pair of vertices (nodes) is connected through a path. If one vertex of a tree is distinguished from the other vertices, then this vertex is called the root and the tree is called a rooted tree.
- Directed rooted tree: A rooted tree where edges are directed from the root to the leaves.
- Depth: The depth of a vertex in a rooted tree is the number of edges of the unique path between this vertex and the root.
- Parent: In a rooted tree a vertex
v
is called parent of a vertexw
ifv
andw
are adjacent (i.e. connected by an edge) and the unique path betweenw
and the root containsv
. Note that each vertex except the root has exactly one parent. - Children: In a rooted tree a vertex
w
is called child of a vertexv
ifv
is the parent ofw
. A vertex may have several children. - N-ary tree: A directed rooted tree where each node has a maximum of
n
children. - Forest: A graph whose connected components are trees.
- Leaf: A leaf
v
is a node with out-degree (i.e., the number of edges havingv
as a target) zero if the input is a directed rooted tree, and a node with degree (i.e., the number of edges incident tov
) one, otherwise. - Subtree: A subtree of a tree
T
is a subgraph ofT
which is also a tree. - Nearest or Lowest or Least common ancestor: The nearest common ancestor of two nodes
u
andv
in a tree graph is the shared ancestor ofu
andv
that is located farthest from the root. - Eccentricity: The eccentricity of a tree node is the maximum distance to any other node.
- Center node: The center of a tree is the set of nodes that have minimal eccentricity.
Type Details
- yfiles module
- algorithms
- yfiles-umd modules
- All layout modules, view-layout-bridge
- Legacy UMD name
- yfiles.algorithms.Trees
Static Methods
Collects all nodes of the subtree starting with root.
Remarks
Parameters
A map of options to pass to the method.
Converts the given tree to a directed rooted tree with the given node as root element by reversing some edges.
Remarks
Preconditions
- The given graph must be a
. - The given node must be part of the given graph.
Parameters
A map of options to pass to the method.
Returns
Returns the center node of an undirected tree.
Remarks
Preconditions
- The graph must be
. - The given graph must be a
.
Parameters
A map of options to pass to the method.
- tree - Graph
- the given undirected tree
Returns
- ↪YNode
- the center node of the given undirected tree
Returns all leaf nodes of the given tree.
Remarks
Note: This method works with instances of Graph. To retrieve all leaf nodes of a directed tree in an IGraph use getLeafNodes instead.
A leaf node is a node with outdegree == 0
if the input is a directed rooted tree, and a node with degree == 1
, otherwise.
Parameters
A map of options to pass to the method.
- tree - Graph
- the given tree
- directedRootedTree - boolean
true
if the algorithm should consider the tree as directed,false
otherwise
Returns
getNearestCommonAncestor
(tree: Graph, root: YNode, rootedDownward: boolean, nodes: YNodeList) : YNodeReturns the nearest common ancestor of a subset of nodes within a directed rooted tree.
Remarks
Note: This method works with instances of Graph. To determine the nearest common ancestor of nodes in a directed tree in an IGraph use getNearestCommonAncestor instead.
It is not part of the given subset.
Complexity
O(tree.N())
Preconditions
- The given graph must be a
.
Parameters
A map of options to pass to the method.
- tree - Graph
- the given directed rooted tree
- root - YNode
- the root of the tree
- rootedDownward - boolean
true
if the tree is directed from the root to the leaves,false
otherwise- nodes - YNodeList
- the subset of nodes
Returns
- ↪YNode
- the nearest common ancestor of the given subset of nodes
Returns a possible root for the given (undirected) tree.
Remarks
Note: This method works with instances of Graph. To determine the root of a directed tree in an IGraph use getRoot instead.
More precisely:
- If the input is a directed rooted tree or reversed directed rooted tree, it returns the corresponding root node.
- If the input is a tree, the method returns a maximum weight center node as defined in getWeightedCenterNode.
- If the input is not a tree, a node with
indegree == 0
(oroutdegree == 0
) is returned.
Preconditions
- The given graph must be a
, or there is exactly one node with indegree == 0
, or there is exactly one node withoutdegree == 0
- The graph must be
.
Parameters
A map of options to pass to the method.
- tree - Graph
- the given tree
Returns
- ↪YNode
- a possible root for the given tree
Returns the depths of each subtree of a rooted directed tree.
Parameters
A map of options to pass to the method.
Returns the size (number of nodes) of each subtree of a rooted directed tree.
Parameters
A map of options to pass to the method.
Returns an array of EdgeList objects each containing edges that belong to a maximal directed subtree of the given graph.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
- treeNodes - YNodeList[]
- an array of YNodeLists previously calculated by getTreeNodes
Returns
Returns an array of YNodeList objects each containing nodes that belong to a maximal directed subtree of the given graph.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
Returns
Returns an array of YNodeList objects each containing nodes that belong to a maximal undirected subtree of the given graph.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
Returns
Finds a node used by the greatest number of all (undirected) paths interconnecting all nodes with each other.
Remarks
Preconditions
- The given graph must be a
(may be undirected). - The graph must be
.
Parameters
A map of options to pass to the method.
- tree - Graph
- the given tree
- intWeight - INodeMap
- the INodeMap that holds the number of paths per node
Domain YNode Values number an value representing the number of paths of each node
Returns
Checks whether or not the given graph is a forest, that is, a graph whose connected components are directed rooted trees.
Checks whether or not the given graph is a forest.
Remarks
Note: This method works with instances of Graph. To determine whether an IGraph is a forest use isForest instead.
If directedRootedTree == true
, each component has to be a directed rooted tree. Otherwise, each component has to be an undirected tree.
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
- directedRootedTree - boolean
true
if the algorithm should check for directed rooted trees,false
otherwise
Returns
- ↪boolean
true
if the given graph is a forest,false
otherwise
isForest(graph, true) => isForest(graph, false)
Checks whether or not the given graph is a directed rooted tree in which each node has a maximum of n
children.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
- n - number
- the allowed maximum of children
Returns
- ↪boolean
true
if the given graph is a n-ary tree,false
otherwise
Checks whether or not the given graph is a directed rooted tree.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
Returns
- ↪boolean
true
if the given graph is a directed rooted tree,false
otherwise
isRootedTree(graph) => isTree(graph)
Checks whether or not the given graph is an undirected tree.
Remarks
Parameters
A map of options to pass to the method.
- graph - Graph
- the given graph
Returns
- ↪boolean
true
if the given graph is an undirected tree,false
otherwise
isRootedTree(graph) => isTree(graph)
.