Skip to content

Commit edf5069

Browse files
authored
Merge pull request kodecocodes#471 from jawwad/patch-6
Fix a few typos in Heap/README
2 parents 90730ad + cde6f85 commit edf5069

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Heap/README.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ An example:
2121

2222
This is a max-heap because every parent node is greater than its children. `(10)` is greater than `(7)` and `(2)`. `(7)` is greater than `(5)` and `(1)`.
2323

24-
As a result of this heap property, a max-heap always stores its largest item at the root of the tree. For a min-heap, the root is always the smallest item in the tree. The heap property is useful because heaps are often used as a [priority queue](../Priority%20Queue/)to access the "most important" element quickly.
24+
As a result of this heap property, a max-heap always stores its largest item at the root of the tree. For a min-heap, the root is always the smallest item in the tree. The heap property is useful because heaps are often used as a [priority queue](../Priority%20Queue/) to access the "most important" element quickly.
2525

2626
> **Note:** The root of the heap has the maximum or minimum element, but the sort order of other elements are not predictable. For example, the maximum element is always at index 0 in a max-heap, but the minimum element isn’t necessarily the last one. -- the only guarantee you have is that it is one of the leaf nodes, but not which one.
2727
@@ -124,7 +124,7 @@ This heap has height 3, so it has 4 levels:
124124

125125
![Large heap](Images/LargeHeap.png)
126126

127-
A heap with *n* nodes has height *h = floor(log_2(n))*. This is because we always fill up the lowest level completely before we add a new level. The example has 15 nodes, so the height is `floor(log_2(15)) = floor(3.91) = 3`.
127+
A heap with *n* nodes has height *h = floor(log2(n))*. This is because we always fill up the lowest level completely before we add a new level. The example has 15 nodes, so the height is `floor(log2(15)) = floor(3.91) = 3`.
128128

129129
If the lowest level is completely full, then that level contains *2^h* nodes. The rest of the tree above it contains *2^h - 1* nodes. Fill in the numbers from the example: the lowest level has 8 nodes, which indeed is `2^3 = 8`. The first three levels contain a total of 7 nodes, i.e. `2^3 - 1 = 8 - 1 = 7`.
130130

@@ -303,7 +303,7 @@ Let's say we want to see if the heap contains the value `8` (it doesn't). We sta
303303

304304
Despite this small optimization, searching is still an **O(n)** operation.
305305

306-
> **Note:** There is away to turn lookups into a **O(1)** operation by keeping an additional dictionary that maps node values to indices. This may be worth doing if you often need to call `replace()` to change the "priority" of objects in a [priority queue](../Priority%20Queue/) that's built on a heap.
306+
> **Note:** There is a way to turn lookups into a **O(1)** operation by keeping an additional dictionary that maps node values to indices. This may be worth doing if you often need to call `replace()` to change the "priority" of objects in a [priority queue](../Priority%20Queue/) that's built on a heap.
307307
308308
## The code
309309

0 commit comments

Comments
 (0)