Class RootedTree<V>
java.lang.Object
org.episteme.core.mathematics.discrete.RootedTree<V>
- All Implemented Interfaces:
Serializable, Graph<V>, Tree<V>
A mutable implementation of a rooted tree.
This implementation stores parent-child relationships efficiently and supports dynamic tree construction. Suitable for:
- Phylogenetic tree construction (UPGMA, Neighbor-Joining)
- Decision tree building
- Hierarchical clustering
- Parse tree construction
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Graph
Graph.Edge<V> -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty tree.RootedTree(V root) Creates a tree with the given root. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child to a parent vertex.booleanAdds an edge between two vertices.booleanAdds a vertex to the graph.intReturns the degree (number of edges) of a vertex.intReturns the number of edges in the tree.Set<Graph.Edge<V>> edges()Returns all edges in this graph.getChildren(V vertex) Returns all children of the given vertex.Returns the parent of the given vertex.getRoot()Returns the root of this tree.Returns neighbors of a vertex.voidSets the root of this tree.Returns the subtree rooted at the given vertex.toString()intReturns the number of vertices in the graph.vertices()Returns all vertices in this graph.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Tree
depth, getAncestors, getDescendants, getLeaves, height, isDirected, isLeaf, isRoot, lowestCommonAncestor, postOrder, postOrderFrom, preOrder, preOrderFrom
-
Constructor Details
-
RootedTree
public RootedTree()Creates an empty tree. -
RootedTree
-
-
Method Details
-
setRoot
-
addChild
-
getRoot
-
getParent
-
getChildren
-
vertices
-
edges
-
addVertex
-
addEdge
-
neighbors
-
degree
-
vertexCount
public int vertexCount()Description copied from interface:GraphReturns the number of vertices in the graph.- Specified by:
vertexCountin interfaceGraph<V>- Returns:
- the number of vertices
-
edgeCount
public int edgeCount()Returns the number of edges in the tree. For a tree with n vertices, this is always n-1.- Returns:
- number of edges
-
subtree
Returns the subtree rooted at the given vertex.- Parameters:
vertex- the root of the subtree- Returns:
- a new tree containing the subtree
-
toString
-