Tree terminology

A tree consists of nodes with a parent-child relationship. Each node has a parent (except for the first node at the top) and zero or more children, as in the following figure:

Tree terminology

The top node of a tree is called the root (11). It is the node that does not have a parent. Each element of the tree is called a node. There are internal nodes and external nodes. An internal node is a node with at least one child (7,5,9,15,13, and 20 are internal nodes). A node that does not have children is called an external node or leaf (3,6,8,10,12,14,18, and 25 are leaves).

A node can have ancestors and descendants. The ancestors of a node (except the ...

Get Learning JavaScript Data Structures and Algorithms - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.