| 1 | Insert 8 at end | 7 | 3 | [10, 15, 30, 40, 50, 100, 40, 8] | New element at index 7 | Array: [10, 15, 30, 40, 50, 100, 40, 8] |
| 2 | Compare with parent | 7 | 3 | [10, 15, 30, 40, 50, 100, 40, 8] | 8 < 40? Yes, swap | Swap index 7 and 3 |
| 3 | After swap | 3 | 1 | [10, 15, 30, 8, 50, 100, 40, 40] | Pointer moves to index 3 | Array: [10, 15, 30, 8, 50, 100, 40, 40] |
| 4 | Compare with parent | 3 | 1 | [10, 15, 30, 8, 50, 100, 40, 40] | 8 < 15? Yes, swap | Swap index 3 and 1 |
| 5 | After swap | 1 | 0 | [10, 8, 30, 15, 50, 100, 40, 40] | Pointer moves to index 1 | Array: [10, 8, 30, 15, 50, 100, 40, 40] |
| 6 | Compare with parent | 1 | 0 | [10, 8, 30, 15, 50, 100, 40, 40] | 8 < 10? Yes, swap | Swap index 1 and 0 |
| 7 | After swap | 0 | - | [8, 10, 30, 15, 50, 100, 40, 40] | Pointer moves to root index 0 | Array: [8, 10, 30, 15, 50, 100, 40, 40] |
| 8 | Compare with parent | 0 | - | [8, 10, 30, 15, 50, 100, 40, 40] | At root, stop bubble up | Final heap restored |