- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hi! (Smile)
A heap is a complete binary tree $T$. That means that a node of the tree has at most two children and for each nonempty subtree $t$ of $T$ it holds that the key of $t$ is greater than all the keys of the left subtree of $t$ and smaller than all the keys of the right subtree of $t$. Also, it holds that each node has exactly two children except from those from the last level. The nodes from the last level don't have children and the last level has to be filled from the left side without lacks but it hasn't to be complete.
The following is for example a heap, right? (Thinking)
View attachment 3737If we want to delete any element of the heap, do we have to put at its position the last element of the heap and then check if the key of the element we put is greater than the keys of the left subtree and smaller than the keys of the right subtree? (Thinking)
A heap is a complete binary tree $T$. That means that a node of the tree has at most two children and for each nonempty subtree $t$ of $T$ it holds that the key of $t$ is greater than all the keys of the left subtree of $t$ and smaller than all the keys of the right subtree of $t$. Also, it holds that each node has exactly two children except from those from the last level. The nodes from the last level don't have children and the last level has to be filled from the left side without lacks but it hasn't to be complete.
The following is for example a heap, right? (Thinking)
View attachment 3737If we want to delete any element of the heap, do we have to put at its position the last element of the heap and then check if the key of the element we put is greater than the keys of the left subtree and smaller than the keys of the right subtree? (Thinking)