Tree Data Structure Terminology

Learn Tree Data Structure Terminology with practical examples, explanations, best practices, and real-world coding techniques.

Understanding Tree Terminology

Trees use a specific vocabulary to describe their structure and the relationships between nodes. Understanding this terminology is important before working with binary trees, Binary Search Trees, heaps, AVL trees, and other tree-based data structures.

Consider the following tree throughout this topic:

              A
            /   \
           B     C
         /  \     \
        D    E     F
            / \
           G   H

Node

A node is an individual element of a tree. It stores a value or other data and may contain references to one or more child nodes.

In the example, A, B, C, D, E, F, G, and H are all nodes.

Node:
A

Data stored:
A

The exact information stored inside a node depends on the type of tree and the application.

Root

The root is the topmost node of a rooted tree. It is the starting point from which all other nodes can be reached.

              A
            /   \
           B     C
         /  \     \
        D    E     F

A is the root of this tree. The root has no parent.

Parent

A parent is a node that has a direct connection to one or more nodes below it.

For example:

  • A is the parent of B and C.
  • B is the parent of D and E.
  • C is the parent of F.
  • E is the parent of G and H.

A node can have multiple children, but each node in a standard rooted tree has only one direct parent except for the root.

Child

A child is a node directly connected below another node.

In the example:

  • B and C are children of A.
  • D and E are children of B.
  • F is a child of C.
  • G and H are children of E.

Siblings

Siblings are nodes that have the same parent.

              A
            /   \
           B     C
         /  \
        D    E

B and C are siblings because they share A as their parent. D and E are also siblings because they share B as their parent.

Leaf Node

A leaf node is a node that has no children. Leaf nodes are also called terminal nodes in many tree-related contexts.

In the example, D, F, G, and H are leaf nodes.

Leaf nodes:

D, F, G, H

Internal Node

An internal node is a node that has at least one child. Internal nodes are sometimes called non-leaf nodes.

In the example, A, B, C, and E are internal nodes.

  • A has children B and C.
  • B has children D and E.
  • C has child F.
  • E has children G and H.

Ancestor

An ancestor of a node is any node that appears on the path from the root to that node, excluding the node itself.

              A
            /   \
           B     C
         /  \
        D    E
            / \
           G   H

For node G:

A → B → E → G

A, B, and E are ancestors of G.

Descendant

A descendant is any node that occurs below another node in the tree.

For example, the descendants of B are:

        B
       / \
      D   E
         / \
        G   H

D, E, G, and H are descendants of B. A descendant does not need to be a direct child.

Degree of a Node

The degree of a node is the number of children that the node has.

Node Children Degree
A B, C 2
B D, E 2
C F 1
D None 0
E G, H 2

A leaf node always has degree 0 because it has no children.

Degree of a Tree

The degree of a tree is the maximum degree of any node in that tree.

In the example, A, B, and E each have two children, while the other nodes have fewer. Therefore, the degree of the tree is 2.

Depth of a Node

The depth of a node is the number of edges on the path from the root to that node. The root has depth 0.

              A        Depth 0
            /   \
           B     C      Depth 1
         /  \     \
        D    E     F    Depth 2
            / \
           G   H         Depth 3
Node Depth
A 0
B, C 1
D, E, F 2
G, H 3

Level of a Node

The level of a node is commonly defined as its depth plus one. Under this convention, the root is at level 1.

              A        Level 1
            /   \
           B     C      Level 2
         /  \     \
        D    E     F    Level 3
            / \
           G   H         Level 4

Some resources use the word "level" interchangeably with depth and start the root at level 0. When solving problems, always check which convention is being used.

Height of a Node

The height of a node is the number of edges on the longest downward path from that node to a leaf.

              A
            /   \
           B     C
         /  \     \
        D    E     F
            / \
           G   H

Node E has height 1 because its longest path to a leaf is E → G or E → H. Node B has height 2 because its longest path is B → E → G. Node A has height 3.

Depth vs Height

Depth and height are related but measure distance in different directions.

Concept Measured From Measured Toward
Depth Root Given node
Height Given node Deepest leaf below it

Path

A path is a sequence of nodes connected by edges. For example, the path from A to H is:

A → B → E → H

The path contains four nodes and three edges.

Path Length

Path length is commonly measured by the number of edges between the nodes in the path. Therefore, the path A → B → E → H has a length of 3.

Subtree

A subtree consists of a node and all of its descendants. Every node can therefore serve as the root of a subtree.

              A
            /   \
           B     C
         /  \
        D    E
            / \
           G   H

The subtree rooted at E is:

        E
       / \
      G   H

Similarly, the subtree rooted at B contains B, D, E, G, and H.

Forest

A forest is a collection of separate trees. If the root of a tree is removed, the remaining connected components can form a forest.

Tree:

        A
       / \
      B   C

Remove A:

   B       C

Forest:
Tree 1: B
Tree 2: C

Branch

A branch refers to a path or sequence of connected nodes extending from a node toward one of its descendants. The term is commonly used to describe one side or direction of a hierarchical tree.

              A
             /
            B
           /
          E
         /
        G

A → B → E → G represents one branch from the root toward a leaf.

Size of a Tree

The size of a tree is the total number of nodes it contains.

              A
            /   \
           B     C
         /  \     \
        D    E     F
            / \
           G   H

Size = 8 nodes

Tree Height

The height of a tree is the height of its root. Using the edge-based definition, the example tree has height 3 because the longest root-to-leaf path contains three edges.

A → B → E → G

Number of edges = 3

Tree height = 3

Quick Reference of Tree Terms

Term Meaning
Node An individual element in a tree
Root Topmost node
Parent A node with direct children
Child A node directly below a parent
Sibling Nodes sharing the same parent
Leaf Node with no children
Internal Node Node with at least one child
Ancestor Node appearing above another node
Descendant Node appearing below another node
Degree Number of children of a node
Depth Number of edges from root to a node
Height Longest downward path to a leaf
Path Sequence of connected nodes
Subtree A node and all of its descendants
Forest A collection of separate trees

Why Tree Terminology Matters

Tree algorithms often describe operations using relationships between nodes rather than individual values. Terms such as ancestor, descendant, subtree, depth, and height appear frequently in algorithm explanations and coding interview questions.

For example, an algorithm might ask for the lowest common ancestor of two nodes, the height of a subtree, the depth of a node, or the number of leaf nodes. Understanding the terminology makes these problems much easier to interpret before writing code.

Common Terminology Mistakes

  • Confusing a node's depth with its height.
  • Calling every node below another node a child instead of distinguishing direct children from descendants.
  • Forgetting that siblings must have the same direct parent.
  • Assuming every non-root node can have multiple parents.
  • Confusing the degree of a node with the degree of the entire tree.
  • Counting nodes instead of edges when a problem defines depth or height using edges.
  • Assuming level numbering always starts at the same value in every problem.

Key Takeaways

  • A node is an individual element of a tree.
  • The root is the topmost node and has no parent.
  • Children are directly connected below a parent.
  • Siblings share the same parent.
  • A leaf has no children, while an internal node has at least one child.
  • Ancestors occur above a node, while descendants occur below it.
  • The degree of a node is its number of children.
  • Depth measures distance from the root to a node.
  • Height measures the longest downward distance from a node to a leaf.
  • A subtree contains a node and all of its descendants.
  • A forest is a collection of separate trees.

Code Examples

class Node {
  constructor(value) {
    this.value = value;
    this.children = [];
  }
}

const root = new Node("A");

const b = new Node("B");
const c = new Node("C");

root.children.push(b, c);

b.children.push(
  new Node("D"),
  new Node("E")
);

c.children.push(
  new Node("F")
);

console.log(root);
    
function treeSize(node) {
  if (node === null) {
    return 0;
  }

  let size = 1;

  for (const child of node.children) {
    size += treeSize(child);
  }

  return size;
}

console.log(treeSize(root));
    
function treeHeight(node) {
  if (node === null || node.children.length === 0) {
    return 0;
  }

  let maxHeight = 0;

  for (const child of node.children) {
    maxHeight = Math.max(
      maxHeight,
      treeHeight(child)
    );
  }

  return maxHeight + 1;
}

console.log(treeHeight(root));
    

Pro Tip

When solving tree problems, first identify the root, parent-child relationships, depth, and height. Many advanced concepts such as lowest common ancestor, subtree queries, and balanced trees become much easier once these terms are clear.

🎨 IgKnight Docs

Master HTML, CSS, JS, Python, .NET and more with easy-to-follow lessons and practical code examples.

© 2025 IgKnight Learning Platform. All rights reserved.