Jul 22, 2024
[3, 1, 6, 5, 2, 4]
1
/
3
### Step 3: Insert 6
- Insert 6 to right of 1
- **Heap is correct**:
1
/
3 6
### Step 4: Insert 5
- Insert 5 to left of 3
- **Heap is correct**
1
/
3 6
/
5
### Step 5: Insert 2
- Insert 2 to right of 3
- Swap 2 with 3
- Swap 2 with 1
- **Heap after swaps**:
1
/
2 6
/
5 3
### Step 6: Insert 4
- Insert 4 to left of 6
- Swap 4 with 6
- **Heap is correct**:
1
/
2 4
/ \ /
5 3 6
## Final Heap as Array
[1, 2, 4, 5, 3, 6]
## Conclusion
- Maintaining the heap property requires checking and potentially swapping positions during each insertion.
- Following this process ensures a functional min-heap.