a)Draw the binary min heap that results from inserting 8, 7, 3, 2, 4, 6, 9, 5, 1 in that order into an initially empty binary min heap. You do not need to show the array representation of the heap. You are only required to show the final tree. (b) Draw the result of one deletemin call on your heap drawn at the end of part (a).
时间: 2024-03-21 18:44:26 浏览: 137
108913_fast-matlab-src.zip_The Count_command5h1_drop6i2_技术
(a) The binary min heap after inserting the given elements is as follows:
```
1
/ \
2 3
/ \ / \
5 4 6 8
/ \
9 7
```
(b) After one deletemin call, the binary min heap becomes:
```
2
/ \
4 3
/ \ / \
5 7 6 8
/
9
```
The minimum element 1 is removed and replaced with the last element 5. Then the heap property is restored by comparing the new root with its children and swapping if necessary. This process is repeated until the heap property is restored.
阅读全文