All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class rpi.goldsd.graph.Tree

java.lang.Object
   |
   +----rpi.goldsd.graph.GraphBase
           |
           +----rpi.goldsd.graph.Tree

public class Tree
extends GraphBase
The Tree class is a subclass of the GraphBase class and is used to represent a tree. A tree is a graph that adheres to the following additional set of requirements:

  1. The graph must be connected.
  2. The graph must be acyclic.
  3. The tree must be rooted at a specified vertex.

Version:
2.1, 5/12/98
Author:
David Goldschmidt
See Also:
GraphBase

Variable Index

 o root
A reference to the root Vertex object of this tree.

Constructor Index

 o Tree()
Default constructor is not used, since a tree must, by definition, have a root vertex.
 o Tree(String, int, int)
Constructs a tree with the specified name, initial vertex hashtable size, and initial edge hashtable size.
 o Tree(Tree)
Constructs a tree by copying another tree.
 o Tree(Vertex)
Constructs an unnamed tree with the specified root vertex.
 o Tree(Vertex, int, int)
Constructs a tree with the specified root vertex, initial vertex hashtable size and initial edge hashtable size.
 o Tree(Vertex, String)
Constructs a tree with the specified root vertex and name.
 o Tree(Vertex, String, int, int)
Constructs a tree with the specified root vertex, name, initial vertex hashtable size, and initial edge hashtable size.

Method Index

 o add(Edge, Vertex)
Adds an edge and corresponding vertex to this tree.
 o clear()
Removes all vertices and edges from this tree, except for the root Vertex object.
 o clone()
Clones this tree.
 o root()
Returns a reference to the root vertex of this tree.

Variables

 o root
 protected Vertex root
A reference to the root Vertex object of this tree.

Constructors

 o Tree
 public Tree(Vertex root,
             String name,
             int vertexTableSize,
             int edgeTableSize)
Constructs a tree with the specified root vertex, name, initial vertex hashtable size, and initial edge hashtable size.

Parameters:
root - the root vertex of this tree.
name - the user-defined name of this tree.
vertexTableSize - the initial hashtable size for the hashtable used to contain the set of vertices.
edgeTableSize - the initial hashtable size for the hashtable used to contain the set of edges.
 o Tree
 protected Tree(String name,
                int vertexTableSize,
                int edgeTableSize)
Constructs a tree with the specified name, initial vertex hashtable size, and initial edge hashtable size. Note that a root vertex is not specified in this protected method; this method is used by the clone() method of the Tree class.

Parameters:
name - the user-defined name of this tree.
vertexTableSize - the initial hashtable size for the hashtable used to contain the set of vertices.
edgeTableSize - the initial hashtable size for the hashtable used to contain the set of edges.
 o Tree
 public Tree(Vertex root,
             int vertexTableSize,
             int edgeTableSize)
Constructs a tree with the specified root vertex, initial vertex hashtable size and initial edge hashtable size.

Parameters:
root - the root vertex of this tree.
vertexTableSize - the initial hashtable size for the hashtable used to contain the set of vertices.
edgeTableSize - the initial hashtable size for the hashtable used to contain the set of edges.
 o Tree
 public Tree(Vertex root,
             String name)
Constructs a tree with the specified root vertex and name.

Parameters:
root - the root vertex of this tree.
name - the user-defined name of this tree.
 o Tree
 public Tree(Tree T)
Constructs a tree by copying another tree.

Parameters:
T - the tree to copy.
 o Tree
 public Tree(Vertex root)
Constructs an unnamed tree with the specified root vertex.

Parameters:
root - the root vertex of this tree.
 o Tree
 protected Tree()
Default constructor is not used, since a tree must, by definition, have a root vertex.

Methods

 o clone
 public Object clone()
Clones this tree.

Returns:
a new tree that is a clone of this tree.
Overrides:
clone in class GraphBase
 o root
 public Vertex root()
Returns a reference to the root vertex of this tree.

Returns:
a reference to the root vertex of this tree.
 o add
 public void add(Edge E,
                 Vertex V) throws DuplicateElementException, InAnotherGraphException, VertexNotFoundException, IllegalArgumentException
Adds an edge and corresponding vertex to this tree. To maintain the properties of a tree, an edge and corresponding vertex must be added as an atomic method. Adding an unattached vertex is not allowed.

The given edge must have an endpoint vertex that exists in this tree and another endpoint vertex that is the second argument V.

Parameters:
E - the edge to be added to this tree.
V - the vertex to be added to this tree.
Throws: IllegalArgumentException
if the vertex and edge arguments are not connected.
Throws: DuplicateElementException
if the key of either the edge or the vertex to be added is already present in the set of edges and vertices, respectively.
Throws: InAnotherGraphException
if the edge or vertex is already in a different graph.
Throws: VertexNotFoundException
if the endpoint vertex that is to already exist in this tree does not exist in this tree.
 o clear
 public void clear()
Removes all vertices and edges from this tree, except for the root Vertex object.

Overrides:
clear in class GraphBase

All Packages  Class Hierarchy  This Package  Previous  Next  Index