You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- A binary tree is called complete binary tree when all the level of binary tree is completely filled except possibly the last level, which is filled from left side to right.
4
+
- Difference between a complete binary tree and a full binary tree is that, in a complete binary tree all leaf nodes should lean towards left and the last nodes need not to have a right sibling.
5
+
6
+
7
+
## Definition of Heap
8
+
According to Wikipedia, a Heap is a special type of binary tree. A heap is a binary tree that meets the following criteria:
9
+
10
+
- Is a complete binary tree;
11
+
- The value of each node must be no greater than (or no less than) the value of its child nodes.
12
+
13
+
A Heap has the following properties:
14
+
- Insertion of an element into the Heap has a time complexity of O(log N);
15
+
- Deletion of an element from the Heap has a time complexity of O(log N);
16
+
- The maximum/minimum value in the Heap can be obtained with O(1) time complexity
17
+
18
+
## Types of Heap
19
+
There are two kinds of heaps: **Max Heap** and **Min Heap**
20
+
21
+
**Max Heap:** Each node in the Heap has a value no less than its child nodes. Therefore, the top element (root node) has the largest value in the Heap.
22
+
23
+
**Min Heap:** Each node in the Heap has a value no larger than its child nodes. Therefore, the top element (root node) has the smallest value in the Heap.
0 commit comments