zaro

What is the Minimum Depth of a Binary Tree?

Published in Tree Depth 2 mins read

The minimum depth of a binary tree is 1. This is the absolute shortest possible depth for any valid binary tree.

Understanding Minimum Depth

The minimum depth of a binary tree is defined as the number of nodes along the shortest path from the root node down to the nearest leaf node. It's crucial to note that this path must end on a leaf node. A leaf node is any node that does not have any children.

The Absolute Minimum: A Depth of 1

A binary tree with the minimum possible depth consists of just one node: the root node. In this specific scenario:

  • The root node is the topmost node of the tree.
  • Since it has no children, this single root node also qualifies as a leaf node.
  • The shortest path from the root node to the nearest (and only) leaf node is simply the root node itself. This path includes only one node.

Therefore, such a tree has a minimum depth of 1.

Examples of Minimum Depth in Binary Trees

Understanding minimum depth can be clarified with various examples:

Tree Structure Description Minimum Depth
Single Node Tree A tree composed of only a root node, which is also a leaf. 1
Root with One Child A tree where the root has one child, and that child is a leaf. 2
Root with Two Children A tree where the root has two children, and both are leaf nodes. 2
Complex Tree with Short Path A tree with multiple levels, but a leaf node exists at the second level (e.g., a root with a child that is a leaf, even if other branches go deeper). 2

For instance, if a binary tree has a root node with a left child, and that left child is a leaf node, the minimum depth would be 2. This is because the shortest path from the root (node 1) to the nearest leaf (node 2, the left child) involves two nodes. Even if the root also has a right child that leads to a much deeper subtree, the minimum depth is determined by the shortest path to any leaf.