liveBook · Manning

Tree height

As explained in Grokking Data Structures

Tree height is the length of the longest path from a tree's root to any leaf, measured in edges or levels according to the chosen convention.

Think of a tree as branching paths from a starting point. Its height is the length of the longest path from the root to any leaf, counted in links. section 11.2

Height also tells you how many levels a tree reaches: level 0 contains the root, level 1 its children, and so on. In a binary heap with n elements, the height grows as O(log n). section 10.11

A path and a subtree

A path such as 0→2→6→3 contains three links, so a tree with that longest path has height 3. The subtree rooted at 8 has height 2. section 11.2

Height strongly affects binary-search-tree performance. Searching follows one root-to-leaf path and takes O(h) comparisons; an unbalanced tree can reach height n, while a balanced tree keeps height O(log n). section 11.17 section 11.8

Visualizes how sorted insertion sequences produce completely skewed trees and maximum height. section 11.17

How Grokking Data Structures covers it

How deep it goes
Defines height with paths and levels, applies it to performance, and defers the mathematical derivation of logarithmic growth.
Examples
Uses a three-link path, a height-two subtree, heap levels, and sorted insertions that create skewed binary search trees.
What it assumes
Defines roots, leaves, paths, children, ancestors, descendants, and subtrees before applying the metric.
What you can do after
Evaluate tree shape and estimate search, insertion, deletion, and related operation costs from the height.
How it connects
Connects tree height with binary trees, heaps, binary search trees, balanced trees, paths, roots, leaves, and subtrees.

Also explained in

Compare how 3 books explain tree height →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Data Structures. The section links point to the parts of the book it draws on.