Skip to main content

What is the height of a tree (height)?

Tree height is the length of the longest path from the root to any leaf, that is, the maximum number of edges between the root and the deepest node.

Definition:

  • The height of a tree with a single node (root only) is 0.
  • If levels are counted starting from 1, height equals the number of levels minus 1.

Example:

javascript
A / \ B C / \ D E
  • Root A is level 0
  • B, C are level 1
  • D, E are level 2 Tree height = 2

Meaning:

Height shows how deep a tree is: how "far" you need to descend from the root to the lowest node.

Summary: Tree height = length of the longest path from the root to a leaf = a measure of the depth and complexity of the structure.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.