Skip to content

Commit af08253

Browse files
authoredFeb 1, 2023
Adding Heap time complexities
1 parent 5fc33c0 commit af08253

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎src/data-structures/heap/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ to the key of `C`
3333
The node at the "top" of the heap with no parents is
3434
called the root node.
3535

36+
## Time Complexities
37+
38+
Here are time complexities of various heap data structures. Function names assume a max-heap.
39+
40+
| Operation | find-max | delete-max | insert| increase-key| meld |
41+
| --------- | -------- | ---------- | ----- | ----------- | ---- |
42+
| [Binary](https://en.wikipedia.org/wiki/Binary_heap) | `Θ(1)` | `Θ(log n)` | `O(log n)` | `O(log n)` | `Θ(n)` |
43+
| [Leftist](https://en.wikipedia.org/wiki/Leftist_tree) | `Θ(1)` | `Θ(log n)` | `Θ(log n)` | `O(log n)` | `Θ(log n)` |
44+
| [Binomial](https://en.wikipedia.org/wiki/Binomial_heap) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `O(log n)` | `O(log n)` |
45+
| [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_heap) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `Θ(1)` | `Θ(1)` |
46+
| [Pairing](https://en.wikipedia.org/wiki/Pairing_heap) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `o(log n)` | `Θ(1)` |
47+
| [Brodal](https://en.wikipedia.org/wiki/Brodal_queue) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `Θ(1)` | `Θ(1)` |
48+
| [Rank-pairing](https://en.wikipedia.org/w/index.php?title=Rank-pairing_heap&action=edit&redlink=1) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `Θ(1)` | `Θ(1)` |
49+
| [Strict Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_heap) | `Θ(1)` | `Θ(log n)` | `Θ(1)` | `Θ(1)` | `Θ(1)` |
50+
| [2-3 heap](https://en.wikipedia.org/wiki/2%E2%80%933_heap) | `O(log n)` | `O(log n)` | `O(log n)` | `Θ(1)` | `?` |
51+
52+
Where:
53+
- **find-max (or find-min):** find a maximum item of a max-heap, or a minimum item of a min-heap, respectively (a.k.a. *peek*)
54+
- **delete-max (or delete-min):** removing the root node of a max heap (or min heap), respectively
55+
- **insert:** adding a new key to the heap (a.k.a., *push*)
56+
- **increase-key or decrease-key:** updating a key within a max- or min-heap, respectively
57+
- **meld:** joining two heaps to form a valid new heap containing all the elements of both, destroying the original heaps.
58+
59+
> In this repository, the [MaxHeap.js](./MaxHeap.js) and [MinHeap.js](./MinHeap.js) are examples of the **Binary** heap.
60+
3661
## References
3762

3863
- [Wikipedia](https://en.wikipedia.org/wiki/Heap_(data_structure))

0 commit comments

Comments
 (0)
Please sign in to comment.