Skip to content

Commit e6d2022

Browse files
author
Antesh Sharma
committed
heap initials
1 parent e6b803c commit e6d2022

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Heap
2+
## Complete Binary Tree Definition
3+
- 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.
24+
25+
![](https://github.com/MissionJava/data-structure-and-algorithm-using-java/tree/main/src/main/java/com/antesh/dsa/heap/min-and-max-heap-diagram.jpg)
Loading

0 commit comments

Comments
 (0)