SlideShare a Scribd company logo
Heap tree
in
Data structure By,
Janani.J
I.Msc IT
V.V.Vannaiperumal college for women,
Objectives…
╸ Heap tree Definition
╸ Max heap tree
╸ Min heap tree
╸ Representation of a heap tree
╸ Operations of a heap tree
╸ Application of heap tree
2
1.Heap tree
Definition…..
HEAP TREE
Definition
A Heap is a complete binary tree.
Suppose H is a complete binary tree.It will be termed heap
tree if it satisfies the following properties:
For each node N in H,the value at N is
greater than or equal to the value of each of the children of N
Or, in other words,N has a value which is
greater than or equal to the value of every successor of N.
There are two types of the heap:
Min Heap
Max heap
4
5
TABLET
PROJECT
Show and explain your web,
app or software projects
using these gadget
templates.
2.Max heap tree
7
Max heap tree
╸ The value of the parent node
should be greater than or equal to
either of its children.
╸ Or
╸ In other words, the max heap can
be defined as for every node I; the
value of node I is less than or
equal to its parent value except
the root node. Mathematically, it
can be defined as:
A[Parent(i)] >= A[i]
3.Min heap tree…
9
Min heap tree
╸ The value of the parent node
should be less than or equal to
either of its children.
╸ Or
╸ In other words, the min-heap can
be defined as, for every node I, the
value of node I is greater than or
equal to its parent value except
the root node. Mathematically, it
can be defined as
A[Parent(i)] <= A[i]
4.Represtation of
a heap tree…
Representative of a heap tree
11
╸ A binary heap is typically represented as array. The
representation is done as:
The root element will be at A[0].
Below table shows indexes of other nodes for the ith node,
i.e., A[i]:
A[(i-1)/2] Returns the parent node
A[(2*i)+1] Returns the left child node
A[(2*i)+2] Returns the right child node
The traversal method use to achieve Array representation is
Level Order
5.Operations of a
heap tree….
Insertion
Merging
Deletion
13
The major operation required to be
performed on a heap tree are:
Insertion of a heap tree
14
╸ Insertion into a heap must maintain both the
complete binary tree structure and the heap order
property.
╸ Its value is compared with its parent’s value,and to
be a Max heap, parent’s value > child’s value is
satisfied, hence the interchange as well as any
further comparison are not required.
╸ Thiis can continue between two nodes on paths
from the newly inserted node to the root node till
We get a parent whose value is greater than its
child or we reach till the root.
Algorithm InsertMaxHeap
Input: ITEM, the data to be interested; the strength of node
Output:ITEM,is inserted into the heap tree.
Data structure: Array A[1……SIZE] storage the heap tree;N being t
the tree.
Steps:
1. If(N≥SIZE)then
2. Print”Heap tree is saturated: Insertion is void”
3. Exit
4. Else
5. N=N+1
6. A[N]=ITEM
7. i=N
8. p=I div 2.
9. While (p>0)and(A[p]<A[I]) do
10. temp=A[I] 15
11. A[I]=A[p]
12. A[p]=temp
13. I=p
14. p=p div 2
15. EndWhile
16.EndIf
17.Stop
16
17
Deletion of a heap tree
The principle can be stated as follows:
• Read the root node into a temporary storage
say,ITEM.
• Replace the root node by the last node in
the heap tree.Then reheap the as stated
below:
• Let the newly modifier root node be the
current node.Compare Its value with the value
of its two children.
• Continue reheap if the current node is not an
empty node.
Algorithm DeleteMaxHeap
Input: A heap tree with elements.
Output:ITEM,is being the data deleted and the remaining tree after de
Data structure: Array A[1……SIZE] storage the heap tree;N is the numb
Steps:
1. If(N=0)then
2. Print”Heap tree is exhausted:Deletion is not possible”
3. Exit
4. Endif
5. ITEM=A[1]
6. A[1]=A[N]
7. N=N-1
8. Flag=FALSE,I=1
9. While (flag=FALSE)and(i<N) do
10. lchild=2*I,rchild=2*I+1
11. . If(lchild≤N)then
12. x=A[lchilld]
13. Else
18
Algorithm DeleteMaxHeap
16. If(rchild≤N)then
17. x=A[rchilld]
18. Else
19. x=-∞
20. EndIf
21. If(A[I]>x) and (A[I]>y) then
22.. Flag=TRUE
23.. Else
24. If(x>y)and (A[i]>x)
25. Swap(A[I],A[lchild])
26. I=lchild
27.. Else
. If(y>x)and (A[i]>y)
Swap(A[I],A[rchild])
I=rchild
28.. EndIf
29.. EndIf
30.. EndIf
31.. EndWhile
32.Stop
19
Deletion of the root node 99 from a
maxheap tree.
20
Vestibulum nec congue
tempus
02
03
01
Merging two heap trees
The merging operation consists of two steps:
Continue steps 1 and 2 while H2 is not empty
1. Delete the root node,say x,from H2.
2.Insert the node x into H1 satisfying the
property of H1.
21
6.Application of
heap tree….
There are two main application of heap trees:
Sorting
Priority queue implementation
Sorting using a heap trees
This actually consists of the following steps:
Step1: Build a heap tree with the given set of data.
Step 2: Delete the root node from the heap.
Rebuild the heap after the deletion.
Place the deleted node in the output
Step 3: Continue step2 until the heap tree is empty.
Application of heap trees
23
IN TWO OR THREE COLUMNS
Yellow
Is the color of gold,
butter and ripe
lemons. In the
spectrum of visible
light, yellow is
found between
green and orange.
Blue
Is the colour of the
clear sky and the
deep sea. It is
located between
violet and green on
the optical
spectrum.
Red
Is the color of
blood, and because
of this it has
historically been
associated with
sacrifice, danger
and courage.
24
AND TABLES TO COMPARE DATA
A B C
Yellow 10 20 7
Blue 30 15 10
Orange 5 24 16
25
Algorithm HeapSort
Input: A set of N input data.
Output: sorted data in ascending order.
Data structure: An Array A where the data will be stored.
Steps:
1. BuildMaxHeap(A)
2. I=N
3. While (I>1) do
4. swap(A[1],A[I])
5. i=i-1
6. j=1
7. While (j<I)do
8. lchild=2*j
9. rchilld=2*j+1
10. If(A[j]<A[lchild]) and (A[lchild]>A[rchilld]) then
11. Swap(A[j],A[lchild])
12. j=lchild
26
Algorithm HeapSort
13.. Else
14. If(A[j]<A[rchild]) and (A[rchild]>A[lchilld]) th
15. Swap(A[j],A[rchild])
j=rchild
16.. Else
17. Break ();
18. EndIf
19. EndIf
20. EndWhile
21.EndWhile
22.Stop
27
Priority queue implementation using
a heap tree
╸ Priority queue can be implemented using a circular
array,a linkedlist, etc.
╸ Another simplified implementation is possible using a
heap tree; the heap, however, can be represented
using an array.
╸ This implementation is therefore free from the
complexities of the circular array and the linked list
but get advantage of simplicity of the array.
28
THANK
you…
:
29

More Related Content

PPT
PPT
1.5 binary search tree
PPT
Binary tree
PPTX
Tree traversal techniques
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
PPTX
Binary Heap Tree, Data Structure
PPT
Binary tree
1.5 binary search tree
Binary tree
Tree traversal techniques
Balanced Tree (AVL Tree & Red-Black Tree)
Binary Heap Tree, Data Structure
Binary tree

What's hot (20)

PPT
Heap tree
PPTX
Stacks IN DATA STRUCTURES
PPTX
Linked List
PPT
Shell sorting
 
PPTX
PPTX
Python dictionary
PPT
BINARY TREE REPRESENTATION.ppt
PDF
Binary Search - Design & Analysis of Algorithms
PPTX
Queue - Data Structure - Notes
PDF
Searching and Sorting Techniques in Data Structure
PPTX
linked list in data structure
PPTX
Graph representation
PPTX
Doubly Linked List
PPTX
trees in data structure
PPTX
PPTX
Binary Tree in Data Structure
PPTX
Stack and queue
PPTX
Linked List - Insertion & Deletion
PPTX
queue & its applications
PPTX
Trees in data structures
Heap tree
Stacks IN DATA STRUCTURES
Linked List
Shell sorting
 
Python dictionary
BINARY TREE REPRESENTATION.ppt
Binary Search - Design & Analysis of Algorithms
Queue - Data Structure - Notes
Searching and Sorting Techniques in Data Structure
linked list in data structure
Graph representation
Doubly Linked List
trees in data structure
Binary Tree in Data Structure
Stack and queue
Linked List - Insertion & Deletion
queue & its applications
Trees in data structures
Ad

Similar to Heap tree (20)

PPTX
Heaptree
PPTX
Array implementation & Construction of Heap
PDF
Heap Hand note
PPTX
heapsort_bydinesh
PPTX
Heap_data_structures_in_data_steruc.pptx
PDF
Heap Tree.pdf
PPT
Unit III Heaps.ppt
PPT
Chapter 12 - Heaps.ppt
PPT
Heapsort ppt
PPTX
Data structures trees and graphs - Heap Tree.pptx
PPTX
Heaps and tries power point this is an educational material
PPTX
heap Sort Algorithm
PPTX
Heap_Sort1.pptx
PPTX
Heap Sort Algorithm
PPT
Heaps & priority queues
PPTX
Weak 14 Heaps - Update.pptx uohogckkjjjkj
PPTX
Heapsort using Heap
PPT
Lec 17 heap data structure
PPT
Analysis of Algorithms-Heapsort
PPTX
05 heap 20161110_jintaeks
Heaptree
Array implementation & Construction of Heap
Heap Hand note
heapsort_bydinesh
Heap_data_structures_in_data_steruc.pptx
Heap Tree.pdf
Unit III Heaps.ppt
Chapter 12 - Heaps.ppt
Heapsort ppt
Data structures trees and graphs - Heap Tree.pptx
Heaps and tries power point this is an educational material
heap Sort Algorithm
Heap_Sort1.pptx
Heap Sort Algorithm
Heaps & priority queues
Weak 14 Heaps - Update.pptx uohogckkjjjkj
Heapsort using Heap
Lec 17 heap data structure
Analysis of Algorithms-Heapsort
05 heap 20161110_jintaeks
Ad

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Institutional Correction lecture only . . .
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPH.pptx obstetrics and gynecology in nursing
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Sports Quiz easy sports quiz sports quiz
Pharma ospi slides which help in ospi learning
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
TR - Agricultural Crops Production NC III.pdf
Renaissance Architecture: A Journey from Faith to Humanism
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Basic Mud Logging Guide for educational purpose
Supply Chain Operations Speaking Notes -ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
RMMM.pdf make it easy to upload and study
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Institutional Correction lecture only . . .

Heap tree

  • 1. Heap tree in Data structure By, Janani.J I.Msc IT V.V.Vannaiperumal college for women,
  • 2. Objectives… ╸ Heap tree Definition ╸ Max heap tree ╸ Min heap tree ╸ Representation of a heap tree ╸ Operations of a heap tree ╸ Application of heap tree 2
  • 4. HEAP TREE Definition A Heap is a complete binary tree. Suppose H is a complete binary tree.It will be termed heap tree if it satisfies the following properties: For each node N in H,the value at N is greater than or equal to the value of each of the children of N Or, in other words,N has a value which is greater than or equal to the value of every successor of N. There are two types of the heap: Min Heap Max heap 4
  • 5. 5 TABLET PROJECT Show and explain your web, app or software projects using these gadget templates.
  • 7. 7 Max heap tree ╸ The value of the parent node should be greater than or equal to either of its children. ╸ Or ╸ In other words, the max heap can be defined as for every node I; the value of node I is less than or equal to its parent value except the root node. Mathematically, it can be defined as: A[Parent(i)] >= A[i]
  • 9. 9 Min heap tree ╸ The value of the parent node should be less than or equal to either of its children. ╸ Or ╸ In other words, the min-heap can be defined as, for every node I, the value of node I is greater than or equal to its parent value except the root node. Mathematically, it can be defined as A[Parent(i)] <= A[i]
  • 11. Representative of a heap tree 11 ╸ A binary heap is typically represented as array. The representation is done as: The root element will be at A[0]. Below table shows indexes of other nodes for the ith node, i.e., A[i]: A[(i-1)/2] Returns the parent node A[(2*i)+1] Returns the left child node A[(2*i)+2] Returns the right child node The traversal method use to achieve Array representation is Level Order
  • 13. Insertion Merging Deletion 13 The major operation required to be performed on a heap tree are:
  • 14. Insertion of a heap tree 14 ╸ Insertion into a heap must maintain both the complete binary tree structure and the heap order property. ╸ Its value is compared with its parent’s value,and to be a Max heap, parent’s value > child’s value is satisfied, hence the interchange as well as any further comparison are not required. ╸ Thiis can continue between two nodes on paths from the newly inserted node to the root node till We get a parent whose value is greater than its child or we reach till the root.
  • 15. Algorithm InsertMaxHeap Input: ITEM, the data to be interested; the strength of node Output:ITEM,is inserted into the heap tree. Data structure: Array A[1……SIZE] storage the heap tree;N being t the tree. Steps: 1. If(N≥SIZE)then 2. Print”Heap tree is saturated: Insertion is void” 3. Exit 4. Else 5. N=N+1 6. A[N]=ITEM 7. i=N 8. p=I div 2. 9. While (p>0)and(A[p]<A[I]) do 10. temp=A[I] 15
  • 16. 11. A[I]=A[p] 12. A[p]=temp 13. I=p 14. p=p div 2 15. EndWhile 16.EndIf 17.Stop 16
  • 17. 17 Deletion of a heap tree The principle can be stated as follows: • Read the root node into a temporary storage say,ITEM. • Replace the root node by the last node in the heap tree.Then reheap the as stated below: • Let the newly modifier root node be the current node.Compare Its value with the value of its two children. • Continue reheap if the current node is not an empty node.
  • 18. Algorithm DeleteMaxHeap Input: A heap tree with elements. Output:ITEM,is being the data deleted and the remaining tree after de Data structure: Array A[1……SIZE] storage the heap tree;N is the numb Steps: 1. If(N=0)then 2. Print”Heap tree is exhausted:Deletion is not possible” 3. Exit 4. Endif 5. ITEM=A[1] 6. A[1]=A[N] 7. N=N-1 8. Flag=FALSE,I=1 9. While (flag=FALSE)and(i<N) do 10. lchild=2*I,rchild=2*I+1 11. . If(lchild≤N)then 12. x=A[lchilld] 13. Else 18
  • 19. Algorithm DeleteMaxHeap 16. If(rchild≤N)then 17. x=A[rchilld] 18. Else 19. x=-∞ 20. EndIf 21. If(A[I]>x) and (A[I]>y) then 22.. Flag=TRUE 23.. Else 24. If(x>y)and (A[i]>x) 25. Swap(A[I],A[lchild]) 26. I=lchild 27.. Else . If(y>x)and (A[i]>y) Swap(A[I],A[rchild]) I=rchild 28.. EndIf 29.. EndIf 30.. EndIf 31.. EndWhile 32.Stop 19
  • 20. Deletion of the root node 99 from a maxheap tree. 20 Vestibulum nec congue tempus 02 03 01
  • 21. Merging two heap trees The merging operation consists of two steps: Continue steps 1 and 2 while H2 is not empty 1. Delete the root node,say x,from H2. 2.Insert the node x into H1 satisfying the property of H1. 21
  • 23. There are two main application of heap trees: Sorting Priority queue implementation Sorting using a heap trees This actually consists of the following steps: Step1: Build a heap tree with the given set of data. Step 2: Delete the root node from the heap. Rebuild the heap after the deletion. Place the deleted node in the output Step 3: Continue step2 until the heap tree is empty. Application of heap trees 23
  • 24. IN TWO OR THREE COLUMNS Yellow Is the color of gold, butter and ripe lemons. In the spectrum of visible light, yellow is found between green and orange. Blue Is the colour of the clear sky and the deep sea. It is located between violet and green on the optical spectrum. Red Is the color of blood, and because of this it has historically been associated with sacrifice, danger and courage. 24
  • 25. AND TABLES TO COMPARE DATA A B C Yellow 10 20 7 Blue 30 15 10 Orange 5 24 16 25
  • 26. Algorithm HeapSort Input: A set of N input data. Output: sorted data in ascending order. Data structure: An Array A where the data will be stored. Steps: 1. BuildMaxHeap(A) 2. I=N 3. While (I>1) do 4. swap(A[1],A[I]) 5. i=i-1 6. j=1 7. While (j<I)do 8. lchild=2*j 9. rchilld=2*j+1 10. If(A[j]<A[lchild]) and (A[lchild]>A[rchilld]) then 11. Swap(A[j],A[lchild]) 12. j=lchild 26
  • 27. Algorithm HeapSort 13.. Else 14. If(A[j]<A[rchild]) and (A[rchild]>A[lchilld]) th 15. Swap(A[j],A[rchild]) j=rchild 16.. Else 17. Break (); 18. EndIf 19. EndIf 20. EndWhile 21.EndWhile 22.Stop 27
  • 28. Priority queue implementation using a heap tree ╸ Priority queue can be implemented using a circular array,a linkedlist, etc. ╸ Another simplified implementation is possible using a heap tree; the heap, however, can be represented using an array. ╸ This implementation is therefore free from the complexities of the circular array and the linked list but get advantage of simplicity of the array. 28