Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Binary Heaps Notes For GATE _ Introduction to Binary Heaps - Data Structures

The document provides comprehensive notes on Binary Heaps, a crucial data structure for GATE exam preparation. It covers definitions, types (Max Heap and Min Heap), representation, construction methods, basic operations, advantages, and disadvantages of heaps. Additionally, it includes practice problems to reinforce understanding of the topic.

Uploaded by

Bhagya Lakshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Binary Heaps Notes For GATE _ Introduction to Binary Heaps - Data Structures

The document provides comprehensive notes on Binary Heaps, a crucial data structure for GATE exam preparation. It covers definitions, types (Max Heap and Min Heap), representation, construction methods, basic operations, advantages, and disadvantages of heaps. Additionally, it includes practice problems to reinforce understanding of the topic.

Uploaded by

Bhagya Lakshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App fo

DOWNLOAD NOW (http://bit.ly/3i8IueA) ×

BYJU'S GATE (/gate/) > GATE (/gate/gate-exam/) > GATE Study Material (/gate/study-material/) > GATE Notes For CSE (/gate/gate-notes-for-cse/) > Introduction to Data structures

(/gate/introduction-to-data-structure-notes/) > Binary Heaps (/gate/binary-heaps-notes/)

(tel:+919241333666)

Binary Heaps Notes For GATE

Binary Heap is an important topic belonging to the famous chapter of Computer Science i.e. Data Structure. And, when it comes to a competitive
examination like GATE, you have to read the whole topic quite deeply. In this article, we have covered all the topics relevant to the binary heap. We
hope the notes for the CSE topics will help you understand this topic in a better way.

Topic of Contents

What are Binary Heaps?

Types of Binary Heaps

How is Binary Heap represented?

Heap Tree Construction

Basic Operations In Binary Heaps

Video on Binary Heap

Advantages of Heap

Disadvantages of Heap

Practice Problems – Binary Heap

What are Binary Heaps?


Binary heap is a data structure. It is like a binary tree in which every node has at most two children at the most. Binary heaps are a standard way of
executing priority queues. It was organized by J. W. J. Williams in 1964 as a data structure for heapsort.

Types of Heaps
There are two types of heaps:

1. Max Heap

2. Min Heap

3. Max Heap: A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the
children of that node.

https://byjus.com/gate/binary-heaps-notes/ 1/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

Start Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

In this picture you can see that the root element has maximum value, which means in the max heap the root element is always greater.

NOTE: This is very important, in the max heap, the parent value should always be greater than a child node at every level.

1. Min Heap: In a Min-Heap the key present at the root node must be less than or equal among the keys present at all of its children.

In this picture, you can see that the root element has minimum value, which means in the min heap the root element is always minimum.

NOTE: This is very important, in the min heap, the parent value should always be smaller than a child node at every level.

How is Binary Heap Represented?


A Binary Heap is like a complete Binary Tree. It is commonly represented as an array.

https://byjus.com/gate/binary-heaps-notes/ 2/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures
Figure: Representation of Binary Heap
Start your FREE GATE Preparation Today (https://ad-
With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

Heap Tree Construction:


When it comes to constructing a heap tree, we can follow two methods:

1. Insert key one by one in the given order

O(nlogn) – Time complexity

Where O is order and n is element

1. Heapify Method

O(n) – Time complexity

Where O is order and n is element

When it comes to creating a heap tree (Min Heap or Max Heap), the heapify method is most suitable, because it takes less time as compared to
the other methods.

Explanation of Picture
In this example we have used Heapify method:

https://byjus.com/gate/binary-heaps-notes/ 3/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures
Heapify → It is a method to rearrange the heap to sustain heap property.
Start your FREE GATE Preparation Today (https://ad-
With BYJU'S Exam Prep Free Trial
In the above picture, we have a set of arrays and we have to create a Max heap from that. Whenever we have to create a tree, we have to start
from the left side. We have created a basic tree that you can see in the picture as “Initial Elements”.

tech.byjusweb.com/revive/www/delivery/cl.php?
Now, to create a max heap, we have to keep one thing in mind that the parent node should be greater than the child node at every level. If you
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
noticed, the second level 3 is a parent node and 8 is a child node. Here, the parent node is smaller than the child node, so we have to swap them.
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)
Once we swap, 8 will take the position of 3.

Now the main parent node has 4 values which are smaller than the child value, we again play swap games and this way we can get the greater
value in the main parent node.

Basic Heap Operations


Insertion → Add a new item to the heap.

Deletion → Delete an item from the heap.

Insertion: Firstly, we have to insert the new element at the end of the heap and we always start from the left side. After inserting the node, we have
to analyze the heap property as the new elements can affect the sequence. We will apply a heapify method to create a proper heap. You can
create a Max or Min heap according to your preference or the question asked in the exam.

Deletion: In the deletion process, we replace the element to be removed by the last rightmost element in the heap. After placing the last element in
place of the deleted one, we have to check whether the heap is following the property of the heap or not. If not, we have to set it according to the
heapify method.

https://byjus.com/gate/binary-heaps-notes/ 4/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

Video on Binary Heap

600

Advantages of Heap
1. Heap data structure preferred graph algorithms.

2. It helps in finding the maximum and minimum elements.

3. Heap is extensively accepted because it is very effective.

https://byjus.com/gate/binary-heaps-notes/ 5/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures
4. The Heap method is also used in the Priority Queue.
Start your FREE GATE Preparation Today (https://ad-
With BYJU'S Exam Prep Free Trial
5. It allows you to access variables globally.

6. Heap doesn’t have any limit on memory size.


tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
NOTE: The major advantage of the binary heap is that you can add new values to it efficiently after initially constructing it.
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)
Disadvantages of Heap
It can provide the maximum memory an OS can provide.

It takes more time to compute.

Memory management is more complicated in heap memory as it is used globally.

It takes too much time in execution compared to the stack.

Practice Problem – Heap


Q. Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4.

Array Index 1 2 3 4 5 6 7 8 9

Value 40 30 20 10 15 16 17 8 4

Now consider that a value 35 is inserted into this heap. After insertion, the new heap is

(A) 40, 30, 20, 10, 15, 16, 17, 8, 4, 35

(B) 40, 35, 20, 10, 30, 16, 17, 8, 4, 15

(C) 40, 30, 20, 10, 35, 16, 17, 8, 4, 15

(D) 40, 35, 20, 10, 15, 16, 17, 8, 4, 30

Q. A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?

(A)

(B)

(C)

(D)

https://byjus.com/gate/binary-heaps-notes/ 6/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

Keep learning and stay tuned to get the latest updates on GATE Exam (https://byjus.com/gate/gate-exam/) along with GATE Eligibility Criteria
(https://byjus.com/gate/gate-eligibility-criteria/), GATE 2023 (https://byjus.com/gate/), GATE Admit Card (https://byjus.com/gate/gate-admit-
card/), GATE Syllabus for CSE (Computer Science Engineering) (https://byjus.com/gate/gate-syllabus-for-computer-science-engineering/), GATE
CSE Notes (https://byjus.com/gate/gate-notes-for-cse/), GATE CSE Question Paper (https://byjus.com/gate/gate-cse-question-paper/), and
more.

Also Explore,

Introduction to Data structures (https://byjus.com/gate/introduction-to-data-structure-notes/)

Introduction to Array Notes (https://byjus.com/gate/array-notes/)

Linked Lists Notes (https://byjus.com/gate/linked-list-notes/)

Heap Sort Notes (https://byjus.com/gate/binary-heap-sort-notes/)

Binary Search Trees Notes (https://byjus.com/gate/binary-search-trees-notes/)

AVL Trees Notes (https://byjus.com/gate/avl-trees-notes/)

Graphs and their Applications (https://byjus.com/gate/graph-and-its-applications/)

Trees (https://byjus.com/gate/tree-notes/)

Stacks and their Applications (https://byjus.com/gate/stack-and-its-applications/)

Queues Notes (https://byjus.com/gate/queue-notes/)

Introduction to Recursion (https://byjus.com/gate/recursion-notes/)

Heap Sort Notes For GATE (https://byjus.com/gate/binary-heap-sort-notes/)

Decimal to Binary Conversion (https://byjus.com/gate/decimal-to-binary-conversion-notes/)

Binary Search Trees (https://byjus.com/gate/binary-search-trees-notes/)

GATE Related Links

Difference Between Javascript (https://byjus.com/gate/difference-between- Put And Post (https://by


And Jquery javascript-and-jquery/) Difference request/)

Difference Between Blog And (https://byjus.com/gate/difference-between-blog-and- Compiler And Interpreter (ht


Vlog vlog/) Difference an

Difference Between Equals (https://byjus.com/gate/difference-between-operator-and-


Tcp And Udp Difference (ht
And In Java equals-method-in-java/)

Difference Between Delete (


GATE EE Syllabus (https://byjus.com/gate/gate-syllabus-for-electrical-engineering/)
Drop And Truncate t

What Is The Difference Between C (https://byjus.com/gate/difference-between-c-and- Difference Between Break (htt


And C++ c-plus-plus/) And Continue con

Comments
Leave a Comment
Your Mobile number and Email id will not be published. Required fields are marked *
*

Mobile Number Send OTP

https://byjus.com/gate/binary-heaps-notes/ 7/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures
*
Start your FREE GATE Preparation Today
Type your message or doubt here...
(https://ad-
With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

Post My Comment

Join BYJU'S Learning Program


Name

Mobile Number

Submit

https://byjus.com/gate/binary-heaps-notes/ 8/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

(https://ad-tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=86&zoneid=111&OXLCA=1&sig=3db76378521bec0285a81b7e6a8da07d85217d30e75f4f11adb618a720fad2f3&dest=https%3A%2F%2Fbyjusexam
test-
series%3FopenLogin%3Dy%26jsdelay%3Dfalse%26utm_campaign%3DbyjusIntegration%26utm_medium%3DTSWidget%26utm_source%3DGovtExam)

https://byjus.com/gate/binary-heaps-notes/ 9/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

(https://ad-tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=140&zoneid=333&OXLCA=1&sig=ccd79e0a55a8e5b9608e31c0c3dfdb360e88822b79068da642840fce9ddf9a79&dest=https%3A%2F%2Fbyju
year-
papers%3FopenLogin%3Dy%26jsdelay%3Dfalse%26utm_campaign%3DbyjusIntegration%26utm_medium%3DPYSP%26utm_source%3DGATE)

https://byjus.com/gate/binary-heaps-notes/ 10/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial

tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)

(https://ad-tech.byjusweb.com/revive/www/delivery/cl.php?
bannerid=141&zoneid=334&OXLCA=1&sig=6676ae51bd547f3c7a2405450200c1681f75006eee40eeaca90ff958c23cc5a2&dest=https%3A%2F%2Fbyjusex
test%2Fgate-exams%3Futm_source%3Dbyjus.com%26utm_medium%3Dgate-sidebanner%26utm_campaign%3Dbyjus-exam-prep-
scholarship-test-2024-21-jan)

Explore Other Popular Articles

Introduction To Array

AVL Trees Notes

Introduction To Data Structures

Linked List Notes

https://byjus.com/gate/binary-heaps-notes/ 11/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures

Start your FREE GATE Preparation Today (https://ad-


With BYJU'S Exam Prep Free Trial
Queue Notes

tech.byjusweb.com/revive/www/delivery/cl.php?
Introduction To Recursion
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)
String In C

Introduction To Tree

Decomposition In DBMS

Derived Data Types In C

COURSES EXAMS

CBSE (/cbse/) CAT Exam (/cat/exam-info/)

ICSE (/icse/) CAT 2023 (/cat/cat-2023/)

CAT (/cat/) GATE Exam (/gate/gate-exam/)

IAS (/ias/) GATE 2024 (/gate/gate-2024/)

JEE (/jee/) IAS Exam (/ias-exam/)

NEET (/neet/) UPSC Exam (/free-ias-prep/upsc-exam/)

Commerce (/commerce/) UPSC Syllabus (/ias/upsc-syllabus/)

JEE Main (/jee/jee-main/) UPSC 2023 (/free-ias-prep/upsc-2023/)

NCERT (/ncert/) Bank Exam (/bank-exam/)

JEE Advanced (/jee-advanced/) Government Exams (/govt-exams/)

UPSC Prelims 2022 Question Paper (/free-ias-prep/upsc-prelims-2022-question-papers-pdf/) Education News (/news/)

UPSC Prelims 2022 Answer Key (/free-ias-prep/upsc-prelims-answer-key-2022/)


CLASSES
IAS Coaching (/ias-coaching/)

CBSE Sample Papers (/cbse/cbse-sample-papers/) Kids Learning (/kids-learning/)

CBSE Question Papers (/cbse-study-material/cbse-previous-year-question-paper/) Class 1st - 3rd (/disney-byjus-early-learn/)

Class 4th - 5th (/class-4-5/)

Class 6th - 10th (/class-6-10/)

Class 11th - 12th (/class-11-12/)

BYJU'S Tuition Centre (/btc/)

EXAM PREPARATION COMPANY

Free CAT Prep (/free-cat-prep/) About Us (/about-us/)

Free IAS Prep (/free-ias-prep/) Contact Us (/contact-us/)

Maths (/maths/) Contact our Financial Partners (https://byjus.com/our-financial-


partners/)
Physics (/physics/)
Investors (/our-investors/)
Chemistry (/chemistry/)
Compliance (/compliance/)
Biology (/biology/)
Careers (/careers-at-byjus/)
JEE 2024 (/jee/jee-2024/)
CIRP (/cirp/)
JEE Advanced 2023 Question Paper with Answers (/jee/jee-advanced-2023-question-paper/)
BYJU'S in Media (/press/)
JEE Main Mock Test (/jee/jee-main-mock-test/)
Social Initiative - Education for All (/educationforall/)
JEE Main 2024 Question Papers with Answers (/jee/jee-main-2024-question-papers/)
BYJU'S APP (/byjus-the-learning-app/)
JEE Main 2023 Question Papers with Answers (/jee/jee-main-2023-question-papers/)
FAQ (/faq/)
JEE Advanced 2022 Question Paper with Answers (/jee/jee-advanced-2022-question-paper/)
Support (/customer-care/)
NEET 2023 Question Paper (/neet/neet-2023-question-paper/)
Students Stories - The Learning Tree (https://blog.byjus.com/the-
NEET 2023 Question Paper Analysis (/neet/neet-2023-question-paper-analysis/)
learning-tree/)
NEET 2022 Answer Key (/neet/neet-2022-answer-key/)
Faces of BYJU'S – Life at BYJU'S (https://blog.byjus.com/life-at-
BYJU'S Exam Prep (https://byjusexamprep.com/) byjus/)

https://byjus.com/gate/binary-heaps-notes/ 12/13
2/14/25, 11:46 AM Binary Heaps Notes For GATE | Introduction to Binary Heaps - Data Structures
RESOURCES Blog (https://blog.byjus.com/)
Start your FREE GATE Preparation Today (https://ad-
CAT College Predictor (/free-cat-prep/cat-college-predictor/) BYJU'S Give (/give/)
With BYJU'S Exam Prep Free Trial
Worksheets (/worksheets/)

BYJU'S Answer (/question-answer/)


tech.byjusweb.com/revive/www/delivery/cl.php?
DSSL (/about-dssl/)
bannerid=82&zoneid=201&sig=9bd29b5e3eed52cfbaa13a2bff86688a551920d65cfe4ac05b71169dbcf79afd&dest=https%3A%2
Home Tuition (/home-tuition/)
fta-gate-hts%3Futm_source%3Dbep_crm%26utm_medium%3Dseo_pages%26utm_campaign%3Dgate_fta)
All Products (https://shop.byjus.com)

Calculators (/calculators/)

Formulas (/formulas/)

FREE TEXTBOOK SOLUTIONS STATE BOARDS

(/textbook-solutions/) Maharashtra (/msbshse/)


NCERT Solutions (/ncert-solutions/)
Gujarat (/gseb/)
NCERT Exemplar (/ncert-exemplar/)
Tamil Nadu (/tn-board/)
NCERT Solutions for Class 6 (/ncert-solutions-class-6/)
Karnataka (/kseeb/)
NCERT Solutions for Class 7 (/ncert-solutions-class-7/)
Kerala (/kbpe/)
NCERT Solutions for Class 8 (/ncert-solutions-class-8/)
Andhra Pradesh (/ap-board/)
NCERT Solutions for Class 9 (/ncert-solutions-class-9/)
Telangana (/telangana-board/)
NCERT Solutions for Class 10 (/ncert-solutions-class-10/)
Uttar Pradesh (/upmsp/)
NCERT Solutions for Class 11 (/ncert-solutions-class-11/)
Bihar (/bihar-board/)
NCERT Solutions for Class 11 English (/ncert-solutions-class-11-english/)
Rajasthan (/rajasthan-board/)
NCERT Solutions for Class 12 English (/ncert-solutions-class-12-english/)
Madhya Pradesh (/mp-board/)
NCERT Solutions for Class 12 (/ncert-solutions-class-12/)
West Bengal (/west-bengal-board/)
RD Sharma Solutions (/rd-sharma-solutions/)

RD Sharma Class 10 Solutions (/rd-sharma-class-10-solutions/)

ICSE Selina Solutions (/icse/selina-solutions/)

FOLLOW US

(https://www.facebook.com/byjuslearningapp/) (https://in.linkedin.com/company/byjus)

Disclaimer (/disclaimer/) Privacy Policy (/tnc_app/#privacydesc) Terms of Services (/tnc_app/#tncdesc) Sitemap (/sitemap.xml)

© 2025, BYJU'S. All rights reserved.

https://byjus.com/gate/binary-heaps-notes/ 13/13

You might also like