🌲 Tree Structure Visualization (Click a node!)
Root Node
Internal Node
Leaf Node
📊 Current Tree Properties
Nodes
10
Edges
9
Height
3
Leaf Nodes
5
Internal Nodes
4
Degree
2
📝 Tree Terminology Dictionary (Click to visualize)
Root
The topmost node of the tree, has no parent
Parent
A node that has child nodes
Child
A lower node connected from a parent
Sibling
Nodes that share the same parent
Leaf
A terminal node with no children
Internal Nodes Internal
A node that has children (excluding leaves)
Ancestor
All nodes on the path to the root
Descendant
All nodes in the subtree of a given node
Depth
Number of edges from root to the node
Height Height
Number of edges from the node to the deepest leaf
📖 Concept Guide
🌳 What is a Tree?
A Tree is a hierarchical data structure consisting of nodes and edges.
💡 Key Properties:
• A single root node exists
• Every node except root has exactly one parent
• No cycles — acyclic connected graph
• A single root node exists
• Every node except root has exactly one parent
• No cycles — acyclic connected graph
Recursive Definition:
- An empty tree is a tree
- A root node r with 0 or more subtrees T₁, T₂, ... Tₖ is a tree
📐 Mathematical Properties of Trees
| Property | Formula |
|---|---|
| Edges | E = N - 1 (N: Nodes) |
| Max nodes in binary tree | 2^h - 1 (h: Height) |
| Max nodes at level k in binary tree | 2^(k-1) |
| Min nodes for height h | h (skewed tree) |
📊 Edges = Nodes - 1
The most fundamental formula that always holds in trees!
10 nodes → 9 edges
The most fundamental formula that always holds in trees!
10 nodes → 9 edges
🌲 Types of Trees
| Type | Features |
|---|---|
| Binary Tree | Each node has at most 2 children |
| Binary Search Tree | Left < Parent < Right |
| Complete Binary Tree | All levels filled except possibly the last |
| Full Binary Tree | All levels are completely filled |
| Balanced Tree | Height difference between left and right ≤ 1 |
| AVL / Red-Black | Self-balancing binary search tree |
| B-Tree | Multi-way search tree, used in databases |
🌍 Real-World Applications of Trees
- File System — Hierarchical structure of folders and files
- HTML DOM — Element structure of web pages
- Database Index — B-Tree, B+Tree
- Decision Tree — Machine learning, AI
- Organization Chart — Company structure
- Family Tree — Family relationships
- Compiler — Abstract Syntax Tree (AST)
- Routing — Network path finding
🎯 Selected Node Info
📍 Click a node
Click a node in the tree to display its detailed information.
🔦 Highlight by Term
💾 Tree Representations
// Complete binary tree array representation
// Index: 0 1 2 3 4 5 6
tree[] = [A, B, C, D, E, F, G]
// Parent: (i-1)/2
// Left child: 2*i + 1
// Right child: 2*i + 2
struct Node {
int data;
Node* left;
Node* right;
};
// Each node links to children via pointers
// Flexible but has memory overhead
// Parent array representation
// parent[i] = parent index of node i
parent[] = [-1, 0, 0, 1, 1, 2, 2]
// Root parent is -1
// Used in Union-Find
📐 Key Formulas
Edges
E = N - 1
Binary tree parent index
(i - 1) / 2
Left/Right child
2i + 1 / 2i + 2
🌍 Real-World Examples
File System — Folder hierarchy
Org Chart — Company structure
HTML DOM — Web element structure