Update README.md

This commit is contained in:
marina 2023-08-02 13:51:00 -07:00 committed by GitHub
parent b53b78285d
commit 29b7948275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,13 +10,13 @@
<br>
* heap is a data structure capable of giving you the smallest (or the largest) element in constant time, while adding or removing the smallest (or the largest) element on logarithmic time.
* a heap is a binary tree with these properties:
* it must have all of **its nodes in a specific order**, and
* its shape must be **complete** (all the levels of the tree must be completely filled except maybe for the last one and the last level must have the left-most nodes filled, always).
* a max heap's **root node must** have all its children either **greater than or equal** to its children. a min heap is the opposite. duplicate values are allowed.
* since you always remove the root, insertion and deletion takes `O(log(N))`. the maximum/minimum value in the heap can be obtained with `O(1)` time complexity.
* heaps can be represented with linked lists or queues (arrays) or binary trees. in the case of a tree to array heap:
* the parent node index is given by `n / 2`
* the left children index is `2 * n`