Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, and 2, one at a time, into an initially empty binary heap.
时间: 2023-10-01 15:05:56 浏览: 149
Sure, I can show you the step-by-step process of inserting these values into an initially empty binary heap:
1. Insert 10:
```
10
```
2. Insert 12:
```
10
/
12
```
3. Insert 1:
```
1
/ \
10 12
```
4. Insert 14:
```
1
/ \
10 12
/
14
```
5. Insert 6:
```
1
/ \
6 12
/ \
10 14
```
6. Insert 5:
```
1
/ \
5 12
/ \ \
10 14 \
6
```
7. Insert 8:
```
1
/ \
5 12
/ \ \
10 14 8
/ \
6 \
9
```
8. Insert 15:
```
1
/ \
5 12
/ \ \
10 14 8
/ \
6 9
/
15
```
9. Insert 3:
```
1
/ \
3 12
/ \ \
10 14 8
/ \
6 9
/ \
15 5
```
10. Insert 9:
```
1
/ \
3 12
/ \ \
10 14 8
/ \
6 9
/ \ /
15 5 9
```
11. Insert 7:
```
1
/ \
3 7
/ \ \
10 14 8
/ \
6 9
/ \ /
15 5 9
/
12
```
12. Insert 4:
```
1
/ \
3 4
/ \ \
10 14 8
/ \
6 9
/ \ /
15 5 9
/ \
12 7
```
13. Insert 11:
```
1
/ \
3 4
/ \ \
10 11 8
/ \
6 9
/ \ /
15 5 9
/ \
12 7
```
14. Insert 13:
```
1
/ \
3 4
/ \ \
10 11 8
/ \
6 9
/ \ /
15 5 13
/ \
12 7
```
15. Insert 2:
```
1
/ \
2 4
/ \ \
3 11 8
/ \
6 9
/ \ /
10 5 13
\
7
```
The final binary heap looks like this:
```
1
/ \
2 4
/ \ / \
3 11 8 7
/ \
6 9
/ \ /
10 5 13
```
阅读全文