Skip to content
BENIBIX Learn

Tree (Data Structure)

Development🧮 Algorithms & Data StructuresData Structures

Also known as Tree, Tree Structure

Nodes joined in a branching shape, with one root at the top and no loops.

Think of it like

Think of it like a family tree. One person is at the top, and the kids are below.

Example

Jack's computer keeps his files in a tree. The home folder is the root, and each photo is a leaf three folders down.

Why it matters

Computers store anything with parents and children as a tree. Files, web pages and menus are all trees.

Definition

A tree is a data structure made of nodes joined in a branching shape. It has one node at the top, called the root. Each node can have child nodes below it, and nodes with no children are called leaves. There are no loops: you can never walk back to where you started. Folders on a computer and the HTML of a web page are both trees.

Common mistake

Picturing the root at the bottom like a real tree. In code the root is drawn at the top.

Key takeaways

  1. 1
    One root. At the top.
  2. 2
    Parents and children. Branching down.
  3. 3
    No loops. One path to each node.

Compare