Fixed typos in MinHeap (#851)
parent
8072446b24
commit
478a8c80c0
|
@ -27,19 +27,19 @@
|
|||
3. If the parent is greater than the element, swap them (move the element one level up), then go to step two.
|
||||
4. Stop if the parent is less or equal.
|
||||
|
||||
> **Note:** second and third steps sift the element up the tree, until correct order of elements is achieved.
|
||||
> **Note:** second and third steps shift the element up the tree, until correct order of elements is achieved.
|
||||
|
||||
**remove min**
|
||||
1. Replace the root with the rightmost element on the deepest level. The new root is now current element.
|
||||
2. Compare the current element with its smallest child.
|
||||
3. If the element is greater than its smallest child, swap the element with its smallest child (move the element one level deeper), and go to step 2.
|
||||
4. If both children are greater or equal to the current element, stop.
|
||||
> **Note:** second and third steps sift the element down the tree until correct order of elements is achieved.
|
||||
> **Note:** second and third steps shift the element down the tree until correct order of elements is achieved.
|
||||
|
||||
## Example
|
||||
|
||||
- **Inserting** elements 4, 10, 2, 22, 45, 18 <br> Output: 2 10 4 22 45 18 <br> Explanation: The numbers are stored subsequently. 2 is the root, 10 and 4 are its children. The children of 10 are 22 and 45. The only child of 4 is 18.
|
||||
- **Deleting** the minimum in 2 10 4 22 45 18 <br> Output: 4 10 18 22 45 <br> Explanation: First, 2 is swapped with 18. Then, 18 is sifted down the tree, until the elements are in correct order. The size of the heap is reduced by 1.
|
||||
- **Deleting** the minimum in 2 10 4 22 45 18 <br> Output: 4 10 18 22 45 <br> Explanation: First, 2 is swapped with 18. Then, 18 is shifted down the tree, until the elements are in correct order. The size of the heap is reduced by 1.
|
||||
|
||||
|
||||
## Implementation
|
||||
|
|
Loading…
Reference in New Issue