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.

RootTopmost node
LeafNode with no children
DepthEdges from root
DegreeNumber of children

Tree operations

400 ms
General tree visualizationInteractive rooted general tree with any number of children per node.

Click a node to select it, then add children or explore its relationships.

Nodes0
Leaves0
Height0
Maximum degree0

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

TermMeaning
RootThe unique topmost node; it has no parent.
Internal nodeA node with at least one child.
LeafA node with no children.
DepthNumber of edges from the root to the node.
HeightLongest number of edges from the node down to a leaf.
DegreeNumber of children of a node.
SubtreeA node together with all of its descendants.