General Tree Simulator
A tree is a hierarchical data structure made of nodes connected by parent-child relationships. Unlike a binary tree, a general tree does not restrict each node to two children. This simulator focuses on the structural ideas shared by many tree data structures: root, parent, child, sibling, leaf, ancestor, descendant, subtree, depth, height, degree, depth-first traversal, and breadth-first traversal.
Tree operations
Click a node to select it, then add children or explore its relationships.
Selected node
Traversal / relationship result
General tree concepts
Parent, child, and sibling
A node may have several children. Nodes with the same parent are siblings.
Ancestor and descendant
Ancestors lie on the path from a node toward the root. Descendants lie inside the node's subtree.
Depth and height
Depth measures distance from the root. Height measures the longest downward path from a node to a leaf.
Degree
The degree of a node is its number of children. The degree of the tree is the maximum node degree.
Subtree
Any node together with all of its descendants forms a subtree.
Traversal
DFS explores one branch deeply before returning; BFS visits nodes level by level using a queue.
Terminology summary
| Term | Meaning |
|---|---|
| Root | The unique topmost node; it has no parent. |
| Internal node | A node with at least one child. |
| Leaf | A node with no children. |
| Depth | Number of edges from the root to the node. |
| Height | Longest number of edges from the node down to a leaf. |
| Degree | Number of children of a node. |
| Subtree | A node together with all of its descendants. |