Trees in Computer Science

A visual, interactive guide to understanding General Trees, Binary Trees, and Binary Search Trees — and how they relate to each other.

scroll to explore
01 — Concept

General Tree

A tree is a hierarchical data structure made of nodes connected by edges. It has exactly one root, and every other node has exactly one parent. A node can have any number of children.

🌳 One root node
Each node → exactly 1 parent
Unlimited children per node
🚫 No cycles allowed

Hover over any node. Notice: nodes can have 0, 1, 2, 3+ children — no limit!

02 — Constraint

Binary Tree

A Binary Tree is a special tree where every node has at most 2 children — called the left child and the right child. No ordering rule exists on the values.

✌️ Max 2 children per node
◀▶ Distinguished left & right
🔀 Values can be in any order

Every node has ≤ 2 children. Values (7, 2, 15 …) are placed without any ordering rule.

03 — Ordering

Binary Search Tree

A BST is a Binary Tree with one extra rule: for every node, all values in the left subtree are smaller and all values in the right subtree are larger. This enables fast O(log n) search.

✌️ Max 2 children (binary)
Left < Parent
Right > Parent
O(log n) search

🧪 Try it — Insert & Search

Insert a number (1–99) and watch it find its place.
04 — Relationships

How They Relate

Every BST is a Binary Tree, and every Binary Tree is a Tree — but not the other way around. They form a strict subset chain.

TREE BINARY TREE Binary Search Tree ordered values BST ⊂ BT ⊂ Tree
General Tree (superset)
Binary Tree (subset of Tree)
BST (subset of Binary Tree)
PropertyTreeBinary TreeBST
Max children per nodeUnlimited22
Values ordered?NoNoYes
Search complexityO(n)O(n)O(log n)*
Left / Right distinctionNoYesYes
Example useFile systems, DOMExpression treesDatabases, indexes

* O(log n) average; O(n) worst case if unbalanced.