SlideShare a Scribd company logo
4
Most read
6
Most read
8
Most read
Heap Data Structure-its application in
shorting domain
Saumya Som
BWU/BCA/17/207
BCA-D (2nd Semester)
Teacher- SOUMIK GUHA ROY
CONTENTS
1 Binary Tree
Types of Binary Tree
Heap Data Structure
Heapsort
Array Representation of
Heaps
Heap Types
2
3
4
5
6
1
Binary
Tree
In a normal tree, every node can
have any number of children.
Binary tree is a special type of
tree data structure in which
every node can have a maximum
of 2 children. One is known as left
child and the other is known as
right child
2
Types of Binary
Tree• Def: Full binary tree = a binary tree in
which each node is either a leaf or has
degree exactly 2.
• Def: Complete binary tree = a binary
tree in which all leaves are on the same
level and all internal nodes have degree
2.
Fig 1:Full binary tree
2
14 8
1
16
7
4
3
9 10
12
Fig 2:Complete binary tree
2
1
16
4
3
9 10
3
Heap Data
Structure
A heap is a nearly complete binary tree with the
following two properties:
• Structural property: all levels are full, except possibly
the last one, which is filled from left to right
• Order (heap) property: for any node x
Parent(x) ≥ x
5
7
8
4
2
Fig 3:Heap
4
Array Representation of Heaps
• A heap can be stored as an
array A.
• Root of tree is A[1]
• Left child of A[i] = A[2i]
• Right child of A[i] = A[2i + 1]
• Parent of A[i] = A[ i/2 ]
Fig 4 :Array Representation of Heaps
5
Heap Types
• Max-heaps (largest element at root), have the max-heap property:
• for all nodes i, excluding the root:
A[PARENT(i)] ≥ A[i]
• Min-heaps (smallest element at root), have the min-heap property:
• for all nodes i, excluding the root:
A[PARENT(i)] ≤ A[i]
MAX Heap
MIN Heap
6
Heapsort
• Goal:
• Sort an array using heap representations
• Idea:
• Build a max-heap from the array
• Swap the root (the maximum element) with the last element in the
array
• Repeat this process until only one node remains
7
Example: 4 1 3 2 16 9 10 14 8 7
2
14 8
1
16
7
4
3
9 10
1
2 3
4 5 6 7
8 9 10
2
14 8
1
16
7
4
3
9 10
1
2 3
4 5 6 7
8 9 10 14
2 8
1
16
7
4
3
9 10
1
2 3
4 5 6 7
8 9 10
14
2 8
1
16
7
4
10
9 3
1
2 3
4 5 6 7
8 9 10
14
2 8
16
7
1
4
10
9 3
1
2 3
4 5 6 7
8 9 10 8
2 4
14
7
1
16
10
9 3
1
2 3
4 5 6 7
8 9 10
 Heap Data Structure

More Related Content

PPT
PPTX
Trees in data structures
PPTX
Binary Heap Tree, Data Structure
PPTX
Polynomial reppresentation using Linkedlist-Application of LL.pptx
PPT
Spanning trees
PPT
Lec 17 heap data structure
PPTX
Bfs new
PPT
Heap sort
Trees in data structures
Binary Heap Tree, Data Structure
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Spanning trees
Lec 17 heap data structure
Bfs new
Heap sort

What's hot (20)

PPTX
Binary Tree in Data Structure
PDF
Expression trees
PPT
Minimum spanning tree
PPTX
Linked list
PDF
Minimum spanning tree
PPTX
Doubly Linked List
PPTX
Searching
PPT
BINARY TREE REPRESENTATION.ppt
PPTX
Topological Sorting
PPTX
Connectivity of graphs
PPT
Linked List
PPT
PDF
Network flow problems
PPTX
Heapify algorithm
PPTX
Heap sort
PPTX
Greedy Algorithms
PDF
Binary search tree operations
PPTX
Kruskal Algorithm
PPTX
Kruskal's algorithm
Binary Tree in Data Structure
Expression trees
Minimum spanning tree
Linked list
Minimum spanning tree
Doubly Linked List
Searching
BINARY TREE REPRESENTATION.ppt
Topological Sorting
Connectivity of graphs
Linked List
Network flow problems
Heapify algorithm
Heap sort
Greedy Algorithms
Binary search tree operations
Kruskal Algorithm
Kruskal's algorithm
Ad

Similar to Heap Data Structure (20)

PDF
PPTX
Tree traversal techniques
PPTX
Array implementation & Construction of Heap
PPTX
Heap Sort Algorithm
PPTX
chapter 6.1.pptx
PPT
Heapsort ppt
PPTX
comparisonbasedsortingalgorithmHeap Sort.pptx
PPTX
Binary Trees.pptx module 122img 787554yau
PPTX
Heap_data_structures_in_data_steruc.pptx
PPT
Unit III Heaps.ppt
PPT
08 B Trees
PDF
dsa prsentation binary tree and its variants.
PPT
3.7 heap sort
PPTX
Heap Sort in Design and Analysis of algorithms
PPTX
Max Heap, Min Heap, Heapify, Heap sort, Build max Heap
PPT
Heapsort
PPT
Heapsort
PPTX
lecture 912345iuhgfdsiuytrewjhgfdsgf.pptx
PPTX
trees in data structure
PPT
CSE680-06HeapSort.ppt
Tree traversal techniques
Array implementation & Construction of Heap
Heap Sort Algorithm
chapter 6.1.pptx
Heapsort ppt
comparisonbasedsortingalgorithmHeap Sort.pptx
Binary Trees.pptx module 122img 787554yau
Heap_data_structures_in_data_steruc.pptx
Unit III Heaps.ppt
08 B Trees
dsa prsentation binary tree and its variants.
3.7 heap sort
Heap Sort in Design and Analysis of algorithms
Max Heap, Min Heap, Heapify, Heap sort, Build max Heap
Heapsort
Heapsort
lecture 912345iuhgfdsiuytrewjhgfdsgf.pptx
trees in data structure
CSE680-06HeapSort.ppt
Ad

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Institutional Correction lecture only . . .
PPTX
Cell Structure & Organelles in detailed.
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial disease of the cardiovascular and lymphatic systems
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
human mycosis Human fungal infections are called human mycosis..pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O7-L3 Supply Chain Operations - ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Abdominal Access Techniques with Prof. Dr. R K Mishra
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Institutional Correction lecture only . . .
Cell Structure & Organelles in detailed.
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
GDM (1) (1).pptx small presentation for students
2.FourierTransform-ShortQuestionswithAnswers.pdf

Heap Data Structure

  • 1. Heap Data Structure-its application in shorting domain Saumya Som BWU/BCA/17/207 BCA-D (2nd Semester) Teacher- SOUMIK GUHA ROY
  • 2. CONTENTS 1 Binary Tree Types of Binary Tree Heap Data Structure Heapsort Array Representation of Heaps Heap Types 2 3 4 5 6
  • 3. 1 Binary Tree In a normal tree, every node can have any number of children. Binary tree is a special type of tree data structure in which every node can have a maximum of 2 children. One is known as left child and the other is known as right child
  • 4. 2 Types of Binary Tree• Def: Full binary tree = a binary tree in which each node is either a leaf or has degree exactly 2. • Def: Complete binary tree = a binary tree in which all leaves are on the same level and all internal nodes have degree 2. Fig 1:Full binary tree 2 14 8 1 16 7 4 3 9 10 12 Fig 2:Complete binary tree 2 1 16 4 3 9 10
  • 5. 3 Heap Data Structure A heap is a nearly complete binary tree with the following two properties: • Structural property: all levels are full, except possibly the last one, which is filled from left to right • Order (heap) property: for any node x Parent(x) ≥ x 5 7 8 4 2 Fig 3:Heap
  • 6. 4 Array Representation of Heaps • A heap can be stored as an array A. • Root of tree is A[1] • Left child of A[i] = A[2i] • Right child of A[i] = A[2i + 1] • Parent of A[i] = A[ i/2 ] Fig 4 :Array Representation of Heaps
  • 7. 5 Heap Types • Max-heaps (largest element at root), have the max-heap property: • for all nodes i, excluding the root: A[PARENT(i)] ≥ A[i] • Min-heaps (smallest element at root), have the min-heap property: • for all nodes i, excluding the root: A[PARENT(i)] ≤ A[i] MAX Heap MIN Heap
  • 8. 6 Heapsort • Goal: • Sort an array using heap representations • Idea: • Build a max-heap from the array • Swap the root (the maximum element) with the last element in the array • Repeat this process until only one node remains
  • 9. 7 Example: 4 1 3 2 16 9 10 14 8 7 2 14 8 1 16 7 4 3 9 10 1 2 3 4 5 6 7 8 9 10 2 14 8 1 16 7 4 3 9 10 1 2 3 4 5 6 7 8 9 10 14 2 8 1 16 7 4 3 9 10 1 2 3 4 5 6 7 8 9 10 14 2 8 1 16 7 4 10 9 3 1 2 3 4 5 6 7 8 9 10 14 2 8 16 7 1 4 10 9 3 1 2 3 4 5 6 7 8 9 10 8 2 4 14 7 1 16 10 9 3 1 2 3 4 5 6 7 8 9 10

Editor's Notes

  • #11: © Copyright Showeet.com