75 Views

heap in data structures with examples


Grag 7th Sep, 2021
Answer (1)
shikha jindal 7th Sep, 2021

A heap is a tree-based data structure in which all the nodes of the tree are in a specific order.

For example, if X is the parent node of Y, then the value of X follows a specific order with respect to the value of Y and the same order will be followed across the tree. The maximum number of children of a node in a heap depends on the type of heap. However, in the more commonly-used heap type, there are at most 2 children of a node and it's known as a Binary heap. In binary heap, if the heap is a complete binary tree with N nodes, then it has smallest possible height which is log N to the base of 2.

Heaps can be of 2 types:

Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree. Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of it’s children. The same property must be recursively true for all sub-trees in that Binary Tree.

Related Questions

Amity University,Noida BBA Ad...
Apply
Ranked amongst top 3% universities globally (QS Rankings)
UPES | BBA Admissions 2024
Apply
#39 in NIRF, NAAC ‘A’ Grade | 100% Placement, up to 30% meritorious scholarships | Last Date to Apply: 31st May
Amity University, Noida B.Tec...
Apply
Asia's Only University with the Highest US & UK Accreditation
IIMT University Meerut BBA Ad...
Apply
"Top 20 Institute of India in Placements" by Times of India | Accredited by NAAC
UPES B.Tech Admissions 2024
Apply
Ranked #52 among universities in India by NIRF | Highest CTC 50 LPA | 100% Placements | Last Date to Apply: 31st May
Jain University B.Tech 2024
Apply
100% Placement Record | Highest CTC 42 LPA | NAAC A++ Accredited | Ranked #68 in India by NIRF Ranking 2023 | Last Date to Apply: 24th May
View All Application Forms

Download the Careers360 App on your Android phone

Regular exam updates, QnA, Predictors, College Applications & E-books now on your Mobile

150M+ Students
30,000+ Colleges
500+ Exams
1500+ E-books