SlideShare a Scribd company logo
Data Structures
(Heap Tree )
Dr.N.S.Nithya
ASP/CSE
12/17/2023 2
Introduction
 Heaps are largely about priority
queues.
 They are an alternative data structure
to implementing priority queues (we
had arrays, linked lists…)
 Recall the advantages and
disadvantages of queues implemented
as arrays
◦ Insertions / deletions? O(n) … O(1)!
 Priority queues are critical to many
real-world applications.
12/17/2023 3
Uses of Heaps
 Use of heap trees can be used to obtain improved
running times for several network optimization
algorithms.
 Can be used to assist in dynamically-allocating
memory partitions.
 Lots of variants of heaps (see Google)
 A heapsort is considered to be one of the best
sorting methods being in-place with no quadratic
worst-case scenarios.
 Finding the min, max, both the min and max,
median, or even the k-th largest element can be
done in linear time using heaps.
 And more….
Heap Data Structures
 Heap data structure is a specialized
binary tree-based data structure. Heap
is a binary tree with special
characteristics. In a heap data
structure, nodes are arranged based
on their values. A heap data structure
some times also called as Binary
Heap.
Properties of Heap data
Structure
 Every heap data structure has the
following properties...
 Property #1 (Structural): All levels in
a heap must be full except the last
level and all nodes must be filled from
left to right strictly.
 Property #2 (Ordering): Nodes must
be arranged in an order according to
their values based on Max heap or
Min heap.
Heaps
A heap is a certain kind
of complete binary tree.
Heaps
A heap is a
certain kind
of complete
binary tree.
When a complete
binary tree is built,
its first node must be
the root.
Root
Heaps
Complete
binary tree.
Left child
of the
root
The second node is
always the left child
of the root.
Heaps
Complete
binary tree.
Right child
of the
root
The third node is
always the right child
of the root.
Heaps
Complete
binary tree.
The next nodes
always fill the next
level from left-to-
right.
Heaps
Complete
binary tree.
The next nodes
always fill the next
level from left-to-
right.
Heaps
Complete
binary tree.
The next nodes
always fill the next
level from left-to-
right.
Heaps
Complete
binary tree.
The next nodes
always fill the next
level from left-to-
right.
Heaps
Complete
binary tree.
Heaps
A heap is a
certain kind
of complete
binary tree.
Each node in a heap
contains a key that
can be compared to
other nodes' keys.
19
4
22
21
27
23
45
35
Heaps
A heap is a
certain kind
of complete
binary tree.
The "heap property"
requires that each
node's key is >= the
keys of its children
19
4
22
21
27
23
45
35
Max Heap
 Max-Heap: In this type of heap, the
value of parent node will always be
greater than or equal to the value of child
node across the tree and the node with
highest value will be the root node of the
tree.
Min Heap
 Min-Heap: In this type of heap, the
value of parent node will always be less
than or equal to the value of child node
across the tree and the node with
lowest value will be the root node of
tree.
Heapify
 Heapify is the process of creating a heap
data structure from a binary tree. It is used
to create a Min-Heap or a Max-Heap.
 Let the input array be
Create a complete binary
tree from the array
Adding a Node to a Max-Heap
 Put the new node (42)
in the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node satisfy the heap
order property.
19
4
22
21
27
23
45
35
42
Adding a Node to a Max-Heap
 Put the new node in
the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node reaches an
acceptable location.
19
4
22
21
42
23
45
35
27
Adding a Node to a Heap
 Put the new node in
the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node reaches an
acceptable location.
19
4
22
21
35
23
45
42
27
Adding a Node to a Max -Heap
 The node move
upwards until it satisfy
the condition
 The parent has a key
that is >= new node
 The process of
pushing the new node
upward is called
reheapification
upward.
19
4
22
21
35
23
45
42
27
Deleting a Max element from Max-
Heap
 To remove the
biggest entry,
move the last
node onto the root,
and perform a
reheapification
downward.
19
4
22
21
35
23
45
42
27
Deleting a Max element from Max-
Heap
 Move the last node
onto the root.
19
4
22
21
35
23
27
42
Deleting a Max element from Max-
Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
4
22
21
35
23
27
42
Deleting a Max element from Max-
Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
4
22
21
35
23
42
27
Deleting a Max element from Max-
Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
4
22
21
27
23
42
35
Deleting a Max element from Max-
Heap
 The children all have
keys <= the out-of-
place node, or
 The node reaches the
leaf.
 The process of
pushing the new node
downward is called
reheapification
downward.
19
4
22
21
27
23
42
35
Adding a Node to a Min-Heap
 Put the new node (5)
in the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node satisfy the heap
order property.
19
24
20
10
14
18
10
12
5
Adding a Node to a Min-Heap
 Put the new node in
the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node reaches an
acceptable location.
19
24
20
15
5
18
10
12
14
Adding a Node to a Min-Heap
 Put the new node in
the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node reaches an
acceptable location.
19
24
20
15
12
18
10
5
14
Adding a Node to a Min-Heap
 Put the new node in
the next available
spot.
 Push the new node
upward, swapping with
its parent until the new
node reaches an
acceptable location.
19
24
20
15
12
18
10
14
5
Adding a Node to a Min -Heap
 The node move
upwards until it satisfy
the condition
 The parent has a key
that is <= new node
 The process of
pushing the new node
upward is called
reheapification
upward.
19
24
20
15
12
18
5
10
14
Deleting a Min element from
Min- Heap
 To remove the
biggest entry,
move the last
node onto the root,
and perform a
reheapification
downward.
19
24
20
15
12
18
4
10
14
Deleting a Min element from
Min- Heap
 Move the last node
onto the root.
19
24
20
15
12
18
14
10
Deleting a Min element from Min-
Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
24
20
15
12
18
14
10
Deleting a Min element from
Min- Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
24
20
15
12
18
10
14
Deleting a Min element from
Min- Heap
 Move the last node
onto the root.
 Push the out-of-place
node downward,
swapping with its
larger child until the
new node reaches an
acceptable location.
19
24
20
15
14
18
10
12
Deleting a Min element from
Min- Heap
 The children all have
keys <= the out-of-
place node, or
 The node reaches the
leaf.
 The process of
pushing the new node
downward is called
reheapification
downward.
19
24
20
15
14
18
10
12
Decrease-Key
 To decrease the value of a certain
key, we’ll use the map to locate its
index. After we locate its index, we’ll
change its value, and start moving it
up the tree if needed. The reason we’re
moving the key up the tree is that its
value got reduced. Therefore, it’ll either
stay in its place or move up.
42
Heap-Priority Queues
 Supports the following operations.
◦ Insert element x.
◦ Return min element.
◦ Return and delete minimum element.
◦ Decrease key of element x to k.
 Applications.
◦ Dijkstra's shortest path algorithm.
◦ Prim's MST algorithm.
◦ Event-driven simulation.
◦ Huffman encoding.
◦ Heapsort.
◦ . . .
Ad

More Related Content

Similar to Data structures trees and graphs - Heap Tree.pptx (20)

heaps
heapsheaps
heaps
Mohamed Elsayed
 
Lec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptxLec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptx
IqraHanif27
 
Heap Hand note
Heap Hand noteHeap Hand note
Heap Hand note
Abdur Rouf
 
Heap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmHeap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap Algorithm
Learning Courses Online
 
Heaps
HeapsHeaps
Heaps
Hoang Nguyen
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Priority queue
Priority queuePriority queue
Priority queue
ManeeshDhiman
 
M.E - Computer Science and Engineering-Data structure unit-2 heaps
M.E - Computer Science and Engineering-Data structure unit-2  heapsM.E - Computer Science and Engineering-Data structure unit-2  heaps
M.E - Computer Science and Engineering-Data structure unit-2 heaps
poonkodiraja2806
 
5-heap.ppt
5-heap.ppt5-heap.ppt
5-heap.ppt
meenamadhuvandhi2
 
5-heap.ppt
5-heap.ppt5-heap.ppt
5-heap.ppt
meenamadhuvandhi2
 
Heap sort
Heap sortHeap sort
Heap sort
GayathriS578276
 
Chapter 12 - Heaps.ppt
Chapter 12 - Heaps.pptChapter 12 - Heaps.ppt
Chapter 12 - Heaps.ppt
MouDhara1
 
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptfdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
KartikGupta711
 
HeapSort
HeapSortHeapSort
HeapSort
Tuqa Rmahi
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6
chidabdu
 
Heapsort
HeapsortHeapsort
Heapsort
Sardar Hussain
 
Array implementation & Construction of Heap
Array implementation & Construction of HeapArray implementation & Construction of Heap
Array implementation & Construction of Heap
Meghaj Mallick
 
Heap Data Structure Tutorial
Heap Data Structure Tutorial Heap Data Structure Tutorial
Heap Data Structure Tutorial
Simplilearn
 
Heaps.pdf
Heaps.pdfHeaps.pdf
Heaps.pdf
KabeerMahmood
 
CSE680-06HeapSort.ppt
CSE680-06HeapSort.pptCSE680-06HeapSort.ppt
CSE680-06HeapSort.ppt
AmitShou
 
Lec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptxLec10-Binary-Heaps-19122022-113509am.pptx
Lec10-Binary-Heaps-19122022-113509am.pptx
IqraHanif27
 
Heap Hand note
Heap Hand noteHeap Hand note
Heap Hand note
Abdur Rouf
 
Heap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap AlgorithmHeap Sort || Heapify Method || Build Max Heap Algorithm
Heap Sort || Heapify Method || Build Max Heap Algorithm
Learning Courses Online
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
M.E - Computer Science and Engineering-Data structure unit-2 heaps
M.E - Computer Science and Engineering-Data structure unit-2  heapsM.E - Computer Science and Engineering-Data structure unit-2  heaps
M.E - Computer Science and Engineering-Data structure unit-2 heaps
poonkodiraja2806
 
Chapter 12 - Heaps.ppt
Chapter 12 - Heaps.pptChapter 12 - Heaps.ppt
Chapter 12 - Heaps.ppt
MouDhara1
 
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.pptfdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
fdocuments.in_branch-and-bound-design-and-analysis-of-alogorithm.ppt
KartikGupta711
 
Algorithm chapter 6
Algorithm chapter 6Algorithm chapter 6
Algorithm chapter 6
chidabdu
 
Array implementation & Construction of Heap
Array implementation & Construction of HeapArray implementation & Construction of Heap
Array implementation & Construction of Heap
Meghaj Mallick
 
Heap Data Structure Tutorial
Heap Data Structure Tutorial Heap Data Structure Tutorial
Heap Data Structure Tutorial
Simplilearn
 
CSE680-06HeapSort.ppt
CSE680-06HeapSort.pptCSE680-06HeapSort.ppt
CSE680-06HeapSort.ppt
AmitShou
 

More from MalligaarjunanN (20)

bro_nodejs-1 front end development .pdf
bro_nodejs-1 front end development  .pdfbro_nodejs-1 front end development  .pdf
bro_nodejs-1 front end development .pdf
MalligaarjunanN
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
MalligaarjunanN
 
8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf
MalligaarjunanN
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
MalligaarjunanN
 
English article power point presentation eng.pptx
English article power point presentation eng.pptxEnglish article power point presentation eng.pptx
English article power point presentation eng.pptx
MalligaarjunanN
 
Digital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxDigital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptx
MalligaarjunanN
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
MalligaarjunanN
 
Polymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxPolymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptx
MalligaarjunanN
 
Chemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxChemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptx
MalligaarjunanN
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
MalligaarjunanN
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
MalligaarjunanN
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
MalligaarjunanN
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
MalligaarjunanN
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
MalligaarjunanN
 
Computer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxComputer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptx
MalligaarjunanN
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
MalligaarjunanN
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
Computer organisation and architecture .
Computer organisation and architecture .Computer organisation and architecture .
Computer organisation and architecture .
MalligaarjunanN
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
MalligaarjunanN
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
MalligaarjunanN
 
bro_nodejs-1 front end development .pdf
bro_nodejs-1 front end development  .pdfbro_nodejs-1 front end development  .pdf
bro_nodejs-1 front end development .pdf
MalligaarjunanN
 
Microprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdfMicroprocessor and microcontroller record.pdf
Microprocessor and microcontroller record.pdf
MalligaarjunanN
 
8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf8087 MICROPROCESSOR and diagram with definition.pdf
8087 MICROPROCESSOR and diagram with definition.pdf
MalligaarjunanN
 
8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical8089 microprocessor with diagram and analytical
8089 microprocessor with diagram and analytical
MalligaarjunanN
 
English article power point presentation eng.pptx
English article power point presentation eng.pptxEnglish article power point presentation eng.pptx
English article power point presentation eng.pptx
MalligaarjunanN
 
Digital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptxDigital principle and computer design Presentation (1).pptx
Digital principle and computer design Presentation (1).pptx
MalligaarjunanN
 
Technical English grammar and tenses.pptx
Technical English grammar and tenses.pptxTechnical English grammar and tenses.pptx
Technical English grammar and tenses.pptx
MalligaarjunanN
 
Polymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptxPolymorphism topic power point presentation li.pptx
Polymorphism topic power point presentation li.pptx
MalligaarjunanN
 
Chemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptxChemistry iconic bond topic chem ppt.pptx
Chemistry iconic bond topic chem ppt.pptx
MalligaarjunanN
 
C programming DOC-20230723-WA0001..pptx
C programming  DOC-20230723-WA0001..pptxC programming  DOC-20230723-WA0001..pptx
C programming DOC-20230723-WA0001..pptx
MalligaarjunanN
 
Chemistry fluorescent topic chemistry.pptx
Chemistry fluorescent topic  chemistry.pptxChemistry fluorescent topic  chemistry.pptx
Chemistry fluorescent topic chemistry.pptx
MalligaarjunanN
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
MalligaarjunanN
 
Inheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptxInheritance_Polymorphism_Overloading_overriding.pptx
Inheritance_Polymorphism_Overloading_overriding.pptx
MalligaarjunanN
 
Python programming file handling mhhk.pptx
Python programming file handling mhhk.pptxPython programming file handling mhhk.pptx
Python programming file handling mhhk.pptx
MalligaarjunanN
 
Computer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptxComputer organisation and architecture updated unit 2 COA ppt.pptx
Computer organisation and architecture updated unit 2 COA ppt.pptx
MalligaarjunanN
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
MalligaarjunanN
 
Data structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptxData structures trees - B Tree & B+Tree.pptx
Data structures trees - B Tree & B+Tree.pptx
MalligaarjunanN
 
Computer organisation and architecture .
Computer organisation and architecture .Computer organisation and architecture .
Computer organisation and architecture .
MalligaarjunanN
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
MalligaarjunanN
 
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptxpythoncommentsandvariables-231016105804-9a780b91 (1).pptx
pythoncommentsandvariables-231016105804-9a780b91 (1).pptx
MalligaarjunanN
 
Ad

Recently uploaded (20)

DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control Monthly May 2025
Water Industry Process Automation & Control
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
roshinijoga
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Working with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to ImplementationWorking with USDOT UTCs: From Conception to Implementation
Working with USDOT UTCs: From Conception to Implementation
Alabama Transportation Assistance Program
 
DED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedungDED KOMINFO detail engginering design gedung
DED KOMINFO detail engginering design gedung
nabilarizqifadhilah1
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdfML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
ML_Unit_VI_DEEP LEARNING_Introduction to ANN.pdf
rameshwarchintamani
 
Lecture - 7 Canals of the topic of the civil engineering
Lecture - 7  Canals of the topic of the civil engineeringLecture - 7  Canals of the topic of the civil engineering
Lecture - 7 Canals of the topic of the civil engineering
MJawadkhan1
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
Efficient Algorithms for Isogeny Computation on Hyperelliptic Curves: Their A...
IJCNCJournal
 
hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .hypermedia_system_revisit_roy_fielding .
hypermedia_system_revisit_roy_fielding .
NABLAS株式会社
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
roshinijoga
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Ad

Data structures trees and graphs - Heap Tree.pptx

  • 1. Data Structures (Heap Tree ) Dr.N.S.Nithya ASP/CSE
  • 2. 12/17/2023 2 Introduction  Heaps are largely about priority queues.  They are an alternative data structure to implementing priority queues (we had arrays, linked lists…)  Recall the advantages and disadvantages of queues implemented as arrays ◦ Insertions / deletions? O(n) … O(1)!  Priority queues are critical to many real-world applications.
  • 3. 12/17/2023 3 Uses of Heaps  Use of heap trees can be used to obtain improved running times for several network optimization algorithms.  Can be used to assist in dynamically-allocating memory partitions.  Lots of variants of heaps (see Google)  A heapsort is considered to be one of the best sorting methods being in-place with no quadratic worst-case scenarios.  Finding the min, max, both the min and max, median, or even the k-th largest element can be done in linear time using heaps.  And more….
  • 4. Heap Data Structures  Heap data structure is a specialized binary tree-based data structure. Heap is a binary tree with special characteristics. In a heap data structure, nodes are arranged based on their values. A heap data structure some times also called as Binary Heap.
  • 5. Properties of Heap data Structure  Every heap data structure has the following properties...  Property #1 (Structural): All levels in a heap must be full except the last level and all nodes must be filled from left to right strictly.  Property #2 (Ordering): Nodes must be arranged in an order according to their values based on Max heap or Min heap.
  • 6. Heaps A heap is a certain kind of complete binary tree.
  • 7. Heaps A heap is a certain kind of complete binary tree. When a complete binary tree is built, its first node must be the root. Root
  • 8. Heaps Complete binary tree. Left child of the root The second node is always the left child of the root.
  • 9. Heaps Complete binary tree. Right child of the root The third node is always the right child of the root.
  • 10. Heaps Complete binary tree. The next nodes always fill the next level from left-to- right.
  • 11. Heaps Complete binary tree. The next nodes always fill the next level from left-to- right.
  • 12. Heaps Complete binary tree. The next nodes always fill the next level from left-to- right.
  • 13. Heaps Complete binary tree. The next nodes always fill the next level from left-to- right.
  • 15. Heaps A heap is a certain kind of complete binary tree. Each node in a heap contains a key that can be compared to other nodes' keys. 19 4 22 21 27 23 45 35
  • 16. Heaps A heap is a certain kind of complete binary tree. The "heap property" requires that each node's key is >= the keys of its children 19 4 22 21 27 23 45 35
  • 17. Max Heap  Max-Heap: In this type of heap, the value of parent node will always be greater than or equal to the value of child node across the tree and the node with highest value will be the root node of the tree.
  • 18. Min Heap  Min-Heap: In this type of heap, the value of parent node will always be less than or equal to the value of child node across the tree and the node with lowest value will be the root node of tree.
  • 19. Heapify  Heapify is the process of creating a heap data structure from a binary tree. It is used to create a Min-Heap or a Max-Heap.  Let the input array be Create a complete binary tree from the array
  • 20. Adding a Node to a Max-Heap  Put the new node (42) in the next available spot.  Push the new node upward, swapping with its parent until the new node satisfy the heap order property. 19 4 22 21 27 23 45 35 42
  • 21. Adding a Node to a Max-Heap  Put the new node in the next available spot.  Push the new node upward, swapping with its parent until the new node reaches an acceptable location. 19 4 22 21 42 23 45 35 27
  • 22. Adding a Node to a Heap  Put the new node in the next available spot.  Push the new node upward, swapping with its parent until the new node reaches an acceptable location. 19 4 22 21 35 23 45 42 27
  • 23. Adding a Node to a Max -Heap  The node move upwards until it satisfy the condition  The parent has a key that is >= new node  The process of pushing the new node upward is called reheapification upward. 19 4 22 21 35 23 45 42 27
  • 24. Deleting a Max element from Max- Heap  To remove the biggest entry, move the last node onto the root, and perform a reheapification downward. 19 4 22 21 35 23 45 42 27
  • 25. Deleting a Max element from Max- Heap  Move the last node onto the root. 19 4 22 21 35 23 27 42
  • 26. Deleting a Max element from Max- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 4 22 21 35 23 27 42
  • 27. Deleting a Max element from Max- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 4 22 21 35 23 42 27
  • 28. Deleting a Max element from Max- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 4 22 21 27 23 42 35
  • 29. Deleting a Max element from Max- Heap  The children all have keys <= the out-of- place node, or  The node reaches the leaf.  The process of pushing the new node downward is called reheapification downward. 19 4 22 21 27 23 42 35
  • 30. Adding a Node to a Min-Heap  Put the new node (5) in the next available spot.  Push the new node upward, swapping with its parent until the new node satisfy the heap order property. 19 24 20 10 14 18 10 12 5
  • 31. Adding a Node to a Min-Heap  Put the new node in the next available spot.  Push the new node upward, swapping with its parent until the new node reaches an acceptable location. 19 24 20 15 5 18 10 12 14
  • 32. Adding a Node to a Min-Heap  Put the new node in the next available spot.  Push the new node upward, swapping with its parent until the new node reaches an acceptable location. 19 24 20 15 12 18 10 5 14
  • 33. Adding a Node to a Min-Heap  Put the new node in the next available spot.  Push the new node upward, swapping with its parent until the new node reaches an acceptable location. 19 24 20 15 12 18 10 14 5
  • 34. Adding a Node to a Min -Heap  The node move upwards until it satisfy the condition  The parent has a key that is <= new node  The process of pushing the new node upward is called reheapification upward. 19 24 20 15 12 18 5 10 14
  • 35. Deleting a Min element from Min- Heap  To remove the biggest entry, move the last node onto the root, and perform a reheapification downward. 19 24 20 15 12 18 4 10 14
  • 36. Deleting a Min element from Min- Heap  Move the last node onto the root. 19 24 20 15 12 18 14 10
  • 37. Deleting a Min element from Min- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 24 20 15 12 18 14 10
  • 38. Deleting a Min element from Min- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 24 20 15 12 18 10 14
  • 39. Deleting a Min element from Min- Heap  Move the last node onto the root.  Push the out-of-place node downward, swapping with its larger child until the new node reaches an acceptable location. 19 24 20 15 14 18 10 12
  • 40. Deleting a Min element from Min- Heap  The children all have keys <= the out-of- place node, or  The node reaches the leaf.  The process of pushing the new node downward is called reheapification downward. 19 24 20 15 14 18 10 12
  • 41. Decrease-Key  To decrease the value of a certain key, we’ll use the map to locate its index. After we locate its index, we’ll change its value, and start moving it up the tree if needed. The reason we’re moving the key up the tree is that its value got reduced. Therefore, it’ll either stay in its place or move up.
  • 42. 42 Heap-Priority Queues  Supports the following operations. ◦ Insert element x. ◦ Return min element. ◦ Return and delete minimum element. ◦ Decrease key of element x to k.  Applications. ◦ Dijkstra's shortest path algorithm. ◦ Prim's MST algorithm. ◦ Event-driven simulation. ◦ Huffman encoding. ◦ Heapsort. ◦ . . .
  翻译: