A tree’s nodes may be assigned a depth and a height. If you would like to brush up on these concepts, then baeldung.com has a great explainer article Difference Between Tree Depth and Height. The difference may be summarised as
Measure | Measures what? The height difference between the node and the most distant member of the zero-reference set: |
node depth | root node |
node height | leaf nodes |
Notice that the definitions of depth and height differ only in which is the zero-reference level for the measurement.
The weakness of current terminology is in two aspects:
- calling the measures ‘depth’ and ‘height’ hides the essential difference between them which is the chosen zero-reference node(s) set.
- there are other possible zero-reference sets (example below) and for all of these other zero-reference sets some nodes will be above the zero-reference (higher or positive elevation) and some nodes will be below the zero-reference (lower or deeper).
Relationship between Height, Depth and Elevation
Elevation is a single scale that incorporates both height and depth. Height is positive, and depth is negative with respect to a zero-reference level. This is shown in the following geographic example.
The zero reference (black line) is sea-level with the highest land at 600m and the deepest water at 700m. This corresponds to elevations between +600m (land height) and -700m (water depth).
Elevation from …
This article argues for replacing node depth and node height with the following:
Existing measure | Elevation from … |
height (+ive) | Elevation from Leaves (+ive) |
depth (+ive) | Elevation from Root (-ive) |
The definition of elevation is exactly as currently defined for height and depth, with the exception that the sign of an elevation below the zero-reference level will be negative.
Other zero-reference levels
Defining elevation in this way allows us to consider other zero-reference levels in a tree. Here is a practical example taken from the domain of Project Management. The tree represents the project Work Breakdown Structure (WBS).
The set of nodes {C, D, H, and K} are the leaf nodes in the WBS and form an interesting zero-reference level for the tree. Let’s call this the “WBS Leaves” zero-reference set.
Here are the Root, Leaves, and WBS Leaves elevations for all nodes:
Node | Root Elevation | WBS Leaves Elevation | Leaves Elevation |
A | 0 | 2 | 3 |
B | -1 | 1 | 2 |
C | -2 | 0 | 0 |
D | -2 | 0 | 1 |
E | -3 | -1 | 0 |
F | -3 | -1 | 0 |
G | -3 | -1 | 0 |
H | -2 | 0 | 1 |
I | -3 | -1 | 0 |
J | -3 | -1 | 0 |
K | -1 | 0 | 0 |
This zero-reference level is useful in Project Management because it allows us to give precise definitions for commonly used terms:
- The WBS consists of all nodes with a non-negative “WBS Leaves” Elevation.
- Summary Elements may be defined as nodes with “WBS Leaves” Elevation greater than zero.
- Work Packages may be defined as nodes with “WBS Leaves” Elevation of 0 and “Leaves” Elevation of 1.
- Planning Packages may be defined as nodes with “WBS Leaves” Elevation of 0 and “Leaves” Elevation of 0.
- Activities may be defined as nodes with “WBS Leaves” Elevation of -1 and “Leaves” Elevation of 0.