Package org.graph4j.util
Class RootedTree
java.lang.Object
org.graph4j.util.RootedTree
Utility class representing a tree with a node designated as root.
- Author:
- Cristian Frăsinaru
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintheight()Returns the height of the tree.booleanisValid()Verifies if the graph is actually a tree.int[]leaves()Returns the leaves (nodes with degree 1).levels()Returns the levels of the tree.int[]parents()Returns an array holding the parents of the vertices in the tree.introot()Returns the designated root of the tree.toString()tree()Returns the tree.
-
Constructor Details
-
RootedTree
Creates a rooted tree. It does not verify if the input graph is actually a tree until specific rooted tree methods are invoked.- Parameters:
tree- the tree.root- the root node.- Throws:
NullPointerException- iftreeisnull.IllegalArgumentException- ifrootis not a vertex number intree.
-
-
Method Details
-
tree
Returns the tree.- Returns:
- the tree.
-
root
public int root()Returns the designated root of the tree.- Returns:
- the root.
-
parents
public int[] parents()Returns an array holding the parents of the vertices in the tree.- Returns:
- the parent array.
- Throws:
NotATreeException- if the graph is not a tree.
-
levels
Returns the levels of the tree.- Returns:
- the levels of the tree.
- Throws:
NotATreeException- if the graph is not a tree.
-
height
public int height()Returns the height of the tree.- Returns:
- the height of the tree.
- Throws:
NotATreeException- if the graph is not a tree.
-
leaves
public int[] leaves()Returns the leaves (nodes with degree 1).- Returns:
- the leaves of the tree.
-
toString
-
isValid
public boolean isValid()Verifies if the graph is actually a tree.- Returns:
trueif the graph is actually a tree,falseotherwise.
-