Trees

Trees

A tree is a dynamic data structure that stores data in a hierarchy rather than a straight line. It captures parent-child relationships, which makes it ideal for file systems, family trees, organization charts, decision processes, and the internal structure of many algorithms. Like a linked list, a tree is built from nodes joined by pointers, but each node may point to several children, producing a branching shape.

Tree terminology

Precise vocabulary is essential for describing and answering questions about trees.

  • Node — a single element of the tree holding data and links to its children.
  • Root — the single node at the very top, the only node with no parent.
  • Parent and child — a node directly above another is its parent; the nodes directly below are its children.
  • Leaf — a node with no child