Concept Definition / Key Idea
Tree Hierarchical structure made of nodes connected by edges
Root Node with no parent
Leaf Node with no children
Siblings Nodes sharing the same parent
Depth Distance from root to node
Height Distance from node to deepest leaf
Subtree A node + all its descendants
Pre-order Visit node before children
Post-order Visit node after children
Depth-first Explore deepest branches first
Breadth-first Explore level by level
ADT Defines behavior (what) — operations allowed
Data Structure Defines implementation (how) — actual code or memory structure

visualising data structures and algorithms through animation - VisuAlgo

A tree is a data structure that shows relationships in a hierarchy — like a family tree or folders on your computer.

Structure and Terms

It’s made up of nodes connected by links (edges).

Each node can have children, and each child has one parent.

  A         ← root (no parent)
 / \\
B   C       ← children of A
/ \\   \\
D  E    F     ← grandchildren of A

<aside> 💡

A tree is either empty, or an object (node) that has a list of subtrees (its children).

</aside>

Term Meaning Example
Root Node with no parent A
Leaf Node with no children D, E, F
Ancestor Parent, grandparent, etc. A and B are ancestors of E
Descendant Children, grandchildren, etc. D, E are descendants of B
Siblings Nodes with the same parent B and C

Depth

The depth of a node means how far it is from the root

in other words, how many edges (connections) you have to travel from the root to reach that node.

Think of it like “how deep down the tree you are.”

  A         ← depth 0
 / \\
B   C       ← depth 1
/ \\   \\
D  E    F     ← depth 2