Class RootedTree

java.lang.Object
org.graph4j.util.RootedTree

public class RootedTree extends Object
Utility class representing a tree with a node designated as root.
Author:
Cristian Frăsinaru
  • Constructor Details

    • RootedTree

      public RootedTree(Graph tree, int root)
      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 - if tree is null.
      IllegalArgumentException - if root is not a vertex number in tree.
  • Method Details

    • tree

      public Graph 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

      public List<VertexSet> 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

      public String toString()
      Overrides:
      toString in class Object
    • isValid

      public boolean isValid()
      Verifies if the graph is actually a tree.
      Returns:
      true if the graph is actually a tree, false otherwise.