liveBook · Manning

Subtree

As explained in Grokking Data Structures

A subtree is a tree consisting of a node and all of its descendants within a larger tree.

Picture a tree branch: choose one node, and keep everything growing below it. That portion is a subtree. Its chosen node is the subtree’s root, and every child of a node begins another subtree. section 11.2

Use the tree figure to see how selecting a node includes that node and all descendants beneath it. section 11.2

In binary trees and binary search trees, subtrees provide the structure behind familiar operations:

  • A binary tree has a left subtree and a right subtree, although the ordering of those children does not always matter. section 11.4
  • In a binary search tree, every value in a node’s left subtree is no greater than the node’s value, while values in its right subtree are greater. section 11.8 section 11.20
  • Search uses these constraints to discard the subtree that cannot contain the target, following only one possible path at each node. section 11.8
  • Because each subtree of a binary search tree is itself a valid binary search tree, maximum and minimum searches can be applied to any subtree. section 11.9

Finding an extreme value

To find the maximum in a subtree, start at its root and repeatedly follow right-child links until reaching a node without a right child. Follow left-child links instead to find the minimum. section 11.9 section 11.9

How Grokking Data Structures covers it

How deep it goes
Defines subtree boundaries and explains their recursive BST behavior, stopping short of broader implementation details.
Examples
Uses left and right BST subtrees, target-search paths, and repeated child-link traversal for minimum and maximum values.
What it assumes
Assumes basic familiarity with nodes and child links while defining descendants, binary trees, and subtree roots directly.
What you can do after
Evaluate tree structure and apply subtree-based search, minimum, and maximum traversals.
How it connects
Connects descendants, binary trees, binary search trees, tree height, search, and maximum and minimum operations.

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.