Skip to main content
← Advanced CS Study Guide

Code Scholars Tutoring · Advanced CS

6.1 Tree Terminology

How it works

Height, depth, leaves, and internal nodes are defined relative to the root. Height measured in edges differs by one from height measured in nodes, so the convention must be stated.

State your convention before answering any height question.

Common error

Mixing edge and node counts between parts of one answer.

Worked example

Example

Root: 8
Left child: 4, with children 2 and 6
Right child: 12
Height convention: number of edges on longest root-to-leaf path

The root has no parent. Leaves have no children. Depth counts edges from the root, while height counts the longest downward path under the stated convention. Always establish whether a course counts height in edges or nodes.

Root 8 has children 4 and 12; node 4 has children 2 and 6.
The leaves are 2, 6, and 12. Root-to-leaf height is 2 edges.

Exercises

6.1.1 · Explain

For the displayed tree, identify the leaves and the depth of node 6.

Show solution

The leaves are 2, 6, and 12. Node 6 has depth 2, following edges 8 to 4 to 6.

6.1.2 · Explain

What are the tree height and the height of a leaf under the stated edge-count convention?

Show solution

The tree height is 2. A leaf has height 0.

Open Java compiler

Need help with this topic?

Work through questions with a tutor and get help with the steps you find difficult.

Get help with this topic