liveBook · Manning

Leaf node

As explained in Grokking Data Structures

A leaf is a tree node that has no child links.

A leaf is a tree node with no child links. Think of it as an endpoint on a branching path: it stores a value but does not lead to another node. Nodes with children are internal nodes. section 11.2

Leaves matter because they mark the ends of tree structure:

  • In a well-formed tree, every path from the root eventually reaches a leaf without visiting the same node twice. section 11.2
  • In a binary tree, a leaf has neither a left nor a right child; nodes with one or two children are internal nodes. section 11.20
  • A leaf is a valid subheap of height zero, making leaves the starting building blocks for bottom-up heap construction. section 10.19

Deleting a leaf

Deleting a leaf is the simplest tree-deletion case because it has no child links to reconnect. After finding the leaf and its parent, sever the link from the parent to that leaf. If the leaf is also the root, removing it leaves an empty tree. section 11.11

How Grokking Data Structures covers it

How deep it goes
Defines leaves structurally and explains their roles in deletion and heapify, without implementing a general tree node.
Examples
Uses tree leaves with values 5, 1, 2, 3, 4, and 7, plus leaf deletion and heapify examples.
What it assumes
Assumes only tree basics such as nodes, links, roots, parents, children, and subtrees.
What you can do after
Apply leaf status to remove terminal nodes and recognize the starting subheaps in bottom-up heap construction.
How it connects
Connects leaves with trees, nodes, parents, children, internal nodes, subtrees, binary heaps, and binary search trees.

Also explained in

Compare how 10 books explain leaf node →

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.