Back to course

Lesson 31: Introduction to Trees (Terminology, Root, Nodes)

Algorithms: From Zero to Hero (A Beginner's Guide)

31. Introduction to Trees (Terminology, Root, Nodes)

A Tree is a non-linear hierarchical data structure consisting of nodes connected by edges, mimicking an upside-down tree.

Key Terminology

  • Root: The topmost node of the tree. A tree can have only one root.
  • Node: The fundamental unit containing data and references/pointers to other nodes.
  • Edge: The link connecting two nodes.
  • Parent: A node immediately above another node.
  • Child: A node immediately below another node.
  • Leaf: A node that has no children.
  • Depth: The length of the path from the root to a specific node.
  • Height: The length of the longest path from the root to any leaf node.

Binary Trees

We will focus primarily on Binary Trees, where every node can have at most two children: a left child and a right child.