Trees come with their own vocabulary: root, parent, leaf, height, depth and so on. These terms appear in every tree algorithm and interview question, so it pays to know them precisely. This page defines each term and points it out on a diagram.

Terminologies in Tree Data Structure
Node:
A node is one element of the tree. It holds a value and references to its child nodes.
For example, the tree below has 6 nodes: A, B, C, D, E and F.

Edge:
An edge is the link between a parent and one of its children. A tree with N nodes always has exactly N − 1 edges, because every node except the root has exactly one edge to its parent.
For example, the line joining A and B below is an edge.

Root Node:
The root is the topmost node. It is the only node with no parent, and every tree has exactly one root.
In the tree below, A is the root.

Parent Node:
A parent is a node that has at least one child, that is, it is directly connected to one or more nodes below it.
In the tree below, A is the parent of B and C, B is the parent of D and E, C is the parent of F, and D is the parent of G.

Child Node:
A child is a node directly below another node and connected to it by an edge. Every node except the root is a child of exactly one parent.
In the tree below, B and C are children of A; D and E are children of B; and F is a child of C.

Sibling:
Siblings are nodes that share the same parent.
In the tree below:
- B and C are siblings.
- D, E and F are siblings.
- G and H are siblings.
- I and J are siblings.

Leaf Node:
A leaf is a node with no children. Leaves are at the ends of the branches and are also called external or terminal nodes.
In the tree below, D, G, I, J and H are leaf nodes.

Degree of a Node:
The degree of a node is the number of children it has. The largest degree of any node is called the degree of the tree.
In the tree below:
- A has degree 2 (children B and C).
- B has degree 3 (children D, E and F).
- C has degree 2 (children G and H).
- E has degree 2 (children I and J).
D, F, G, H, I and J have degree 0 because they have no children; every leaf has degree 0. The degree of this tree is 3.

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. Every leaf has height 0, and the height of the root is the height of the tree.
In the tree below, the root 50 has height 3 (for example 50 → 68 → 43 → 58).

Depth of a node:
The depth of a node is the number of edges on the path from the root down to that node. The root always has depth 0.
In the tree below, every node on the same horizontal row has the same depth.

Path:
A path is the sequence of nodes and edges that leads from one node to another. Its length is usually counted as the number of edges on it.
The highlighted path below runs from 21 up to the root 50 and down to 28; it has 6 edges.

Ancestor of a Node:
The ancestors of a node are all the nodes on the path from that node up to the root (its parent, its parent's parent, and so on).
In the tree below, the ancestors of node D are B and A.

Descendant:
A node x is a descendant of node y if y is an ancestor of x; in other words, x lies somewhere in the subtree below y.
For example, node H is a descendant of node C in the tree below.

Level of a node:
The level of a node tells how far down the tree it is. The root is at level 0, its children at level 1, their children at level 2, and so on; with this convention the level equals the depth.

Internal node:
An internal (non-terminal) node is a node with at least one child. A node is therefore either internal or a leaf, never both.
In the tree below, A, B, C, E and G are internal nodes, and all other nodes are leaves.

Neighbour of a Node:
The neighbours of a node are the nodes directly connected to it by an edge: its parent and its children.
In the tree below, C and H are neighbours.

Subtree:
A subtree is a node together with all of its descendants. Every child of a node is the root of its own subtree, which is why most tree algorithms are written recursively.
