Package com.jgalgo.alg.tree
Class Trees
java.lang.Object
com.jgalgo.alg.tree.Trees
Static methods class for tree graphs.
- Author:
- Barak Ugav
-
Method Summary
-
Method Details
-
isTree
Check if an undirected graph is a tree.An undirected graph is a tree if its connected and contains no cycle, therefore \(n-1\) edges.
This method runs in linear time.
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graph- Returns:
true
if the graph is a tree, elsefalse
- Throws:
IllegalArgumentException
- ifg
is a directed graph
-
isTree
Check if a graph is a tree rooted as some vertex.For undirected graphs, a graph which is a tree rooted at some vertex can be rooted at any other vertex and will always be a tree. For directed graphs however this is not true. A directed graph might be a tree rooted at some vertex, but will no be connected if we root it at another vertex.
This method runs in linear time.
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graphroot
- a root vertex- Returns:
true
if the graph is a tree rooted atroot
, elsefalse
.
-
isForest
Check if a graph is a forest.A forest is a graph which can be divided into trees, which is equivalent to saying a graph with no cycles.
This method runs in linear time.
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- a graph- Returns:
true
if the graph is a forest, elsefalse
-