| 1 | Create new node with value 25 | ∅ | new_node = Node(25) | ∅ |
| 2 | Check if root is null | root = ∅ | root = new_node | ┌────────┐
│ data:25│
│ left:∅ │
│ right:∅│
└────────┘
root |
| 3 | Insert complete | root = 25 | No change | ┌────────┐
│ data:25│
│ left:∅ │
│ right:∅│
└────────┘
root |
| 4 | Create new node with value 15 | root = 25 | new_node = Node(15) | ┌────────┐
│ data:25│
│ left:∅ │
│ right:∅│
└────────┘
root |
| 5 | Compare 15 with 25 (current root) | current = 25 | Move left since 15 < 25 | ┌────────┐ ∅
│ data:25│──→ ∅
│ left:∅ │
│ right:∅│
└────────┘
root |
| 6 | Left child is null, insert new node here | current = 25 | current.left = new_node(15) | ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│
│ left:──┼ │ left:∅ │
│ right:∅│ │ right:∅│
└────────┘ └────────┘
root left child |
| 7 | Insert complete | root = 25 | No change | ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│
│ left:──┼ │ left:∅ │
│ right:∅│ │ right:∅│
└────────┘ └────────┘
root left child |
| 8 | Create new node with value 35 | root = 25 | new_node = Node(35) | ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│
│ left:──┼ │ left:∅ │
│ right:∅│ │ right:∅│
└────────┘ └────────┘
root left child |
| 9 | Compare 35 with 25 (current root) | current = 25 | Move right since 35 > 25 | ┌────────┐ ∅
│ data:25│──→ ∅
│ left:──┼
│ right:∅│
└────────┘
root |
| 10 | Right child is null, insert new node here | current = 25 | current.right = new_node(35) | ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│
│ left:──┼ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘
root left child right child |
| 11 | Insert complete | root = 25 | No change | ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│
│ left:──┼ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘
root left child right child |
| 12 | Create new node with value 20 | root = 25 | new_node = Node(20) | ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│
│ left:──┼ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘
root left child right child |
| 13 | Compare 20 with 25 (root) | current = 25 | Move left since 20 < 25 | ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│
│ left:──┼ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘
root left child right child |
| 14 | Compare 20 with 15 (left child) | current = 15 | Move right since 20 > 15 | ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│
│ left:──┼ │ left:∅ │ │ left:∅ │
│ right:∅│──→ ∅ │ right:∅│
└────────┘ └────────┘ └────────┘
root left child right child |
| 15 | Right child of 15 is null, insert new node here | current = 15 | current.right = new_node(20) | ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│ │ data:20│
│ left:──┼ │ left:∅ │ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘ └────────┘
root left child right child right child of 15 |
| 16 | Insert complete | root = 25 | No change | ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐
│ data:25│──→ │ data:15│ │ data:35│ │ data:20│
│ left:──┼ │ left:∅ │ │ left:∅ │ │ left:∅ │
│ right:─┼──→ │ right:∅│ │ right:∅│ │ right:∅│
└────────┘ └────────┘ └────────┘ └────────┘
root left child right child right child of 15 |