Professional Documents
Culture Documents
Data Structure: Chapter 5 - Trees 5.6 5.10
Data Structure: Chapter 5 - Trees 5.6 5.10
Data Structure: Chapter 5 - Trees 5.6 5.10
Anand Paul
Hanyang University
anand@hanyang.ac.kr
Heaps
• Heaps: a binary tree structure with the properties …
– The tree is complete.
– The key value of each node is greater than or equal to
the key value in each of its descendents (MAX heap)
2
priority queues
• used to implement priority queues
– delete the element with highest (or lowest)
priority
– insert an element with arbitrary priority into
the queue
• a data structure that supports these two operations:
a max(min) priority queue
3
priority queues (Cont.)
• MaxPQ
– can be realized by # of different data structures
• unordered list
• ordered list
– impossible to implement the MaxPQ operations without knowing
the data structures
5
Definition of a max heap (Cont.)
• a max heap
• a max heap 의 기본 연산
• Creation of an empty heap
• Insertion of a new element into the heap
• Deletion of the largest element from the heap
7
Insertion into a max heap
(Cont.)
• to implement the heap insertion
– need to go from an element to its parent
– assume heap[n++] is the location to be inserted
8
Deletion from a max heap
• Figure 5.28(a) : a deletion from the heap
of Figure 5.27(d)
• remove 21, result in empty root node
• remove the element in position 6 (the element 2)
• insert 2 into the root
• move 20 into the root
9
Deletion from a max heap
(Cont.)
10