Skip to content

Commit 2337536

Browse files
committed
Fix #59.
1 parent 281e4dc commit 2337536

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

docs/02-heap-complexity/binary-heap.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,18 @@ Input:
266266
Output: None, restore the element in place
267267
Steps:
268268
1. current_i = i # current index starting from input i
269-
2. swapped = True
270-
3. As long as ( left(current_i) < length of array) AND swapped, do:
271-
3.1 swapped = False
272-
3.2 max_child_i = get the index of largest child of the node current_i
273-
3.3 if array[max_child_i] > array[current_i], do:
274-
3.3.1 swap( array[max_child_i], array[current_i])
275-
3.3.2 swapped = True
276-
3.3 current_i = max_child_i # move to the index of the largest child
269+
2. As long as ( left(current_i) < length of array) AND swapped, do:
270+
2.1 max_child_i = get the index of largest child of the node current_i
271+
2.2 if array[max_child_i] > array[current_i], do:
272+
2.2.1 swap( array[max_child_i], array[current_i])
273+
2.3 otherwise:
274+
2.3.1 exit loop
275+
2.4 current_i = max_child_i # move to the index of the largest child
277276
```
278277

279278
</DeepDive>
280279

281-
We introduced a boolean variable called `swapped`. At every iteration, we set `swapped` to `False`. If there is a swap, we set this boolean variable to `True` and continues to the next iteration. If there is no swap, the boolean variable is still `False` and so it will stop the iteration.
280+
If there is a swap, we continue to the next iteration. If there is no swap, we will break from the loop and it will stop the iteration.
282281

283282
## Building A Heap
284283

0 commit comments

Comments
 (0)