SlideShare a Scribd company logo
Priority Queues (Heaps)Priority Queues (Heaps)
111111Cpt S 223. School of EECS, WSU
Motivation
 Queues are a standard mechanism for ordering tasks
on a first-come, first-served basis
 However, some tasks may be more important or
timely than others (higher priority)
 Priority queues Priority queues
 Store tasks using a partial ordering based on priority
 Ensure highest priority task at head of queue
 Heaps are the underlying data structure of priority
queues
22222Cpt S 223. School of EECS, WSU
Priority Queues: Specification
 Main operations
 insert (i.e., enqueue)
D i i t Dynamic insert
 specification of a priority level (0-high, 1,2.. Low)
 deleteMin (i.e., dequeue)
 Finds the current minimum element (read: “highest priority”) in
the queue, deletes it from the queue, and returns it
 Performance goal is for operations to be “fast”
3Cpt S 223. School of EECS, WSU
Using priority queues
5 3
10
13
19
4
13 8
2211
insert()
deleteMin()
2
Dequeues the next element
with the highest prioritywith the highest priority
4Cpt S 223. School of EECS, WSU
Can we build a data structure better suited to store and retrieve priorities?
Simple Implementations
 Unordered linked list
 O(1) insert
 O(n) deleteMin
5 2 10 3…
 O(n) deleteMin
 Ordered linked list
 O(n) insert
O(1) d l t Mi
2 3 5 10…
 O(1) deleteMin
 Ordered array
 O(lg n + n) insert
2 3 5 … 10
 O(n) deleteMin
 Balanced BST
 O(log2n) insert and deleteMin O(log2n) insert and deleteMin
55Cpt S 223. School of EECS, WSU
Bi HBinary Heap
A priority queue data structure
6Cpt S 223. School of EECS, WSU
Binary Heap
 A binary heap is a binary tree with two
propertiesproperties
 Structure property
 Heap-order property Heap order property
7Cpt S 223. School of EECS, WSU
Structure Property
 A binary heap is a complete binary tree
 Each level (except possibly the bottom most level)( p p y )
is completely filled
 The bottom most level may be partially filled
(f l ft t i ht)(from left to right)
 Height of a complete binary tree with N
elements is  N2log
88Cpt S 223. School of EECS, WSU
Structure property
Binary Heap Example
N=10
Every level
(except last)
saturated
Array representation:
9Cpt S 223. School of EECS, WSU
Heap-order Property
 Heap-order property (for a “MinHeap”)
 For every node X key(parent(X)) ≤ key(X) For every node X, key(parent(X)) ≤ key(X)
 Except root node, which has no parent
Thus minimum key always at root Thus, minimum key always at root
 Alternatively, for a “MaxHeap”, always
keep the maximum key at the rootkeep the maximum key at the root
 Insert and deleteMin must maintain
heap order propertyheap-order property
10Cpt S 223. School of EECS, WSU
Heap Order Property
Minimum
element
 
   
   
 Duplicates are allowed
  
 Duplicates are allowed
 No order implied for elements which do not
share ancestor-descendant relationshipshare ancestor descendant relationship
11Cpt S 223. School of EECS, WSU
Implementing Complete
Binary Trees as Arrays
 Given element at position i in the array
 Left child(i) = at position 2i Left child(i) at position 2i
 Right child(i) = at position 2i + 1
 Parent(i) = at position  2/i Parent(i) = at position  2/i
2i
2i + 1
i
i/2
12
i/2
Cpt S 223. School of EECS, WSU
Just finds the Min
insert
Just finds the Min
without deleting it
deleteMin
Note: a general delete()
function is not as important
for heaps
but could be implemented
Stores the heap as
a vector
Fix heap after
13
p
deleteMin
Cpt S 223. School of EECS, WSU
Heap Insert
 Insert new element into the heap at the
next available slot (“hole”)next available slot ( hole )
 According to maintaining a complete binary
tree
 Then, “percolate” the element up the
heap while heap-order property notheap while heap order property not
satisfied
14Cpt S 223. School of EECS, WSU
Percolating Up
Heap Insert: Example
Insert 14:
hole14
15Cpt S 223. School of EECS, WSU
Percolating Up
Heap Insert: Example
Insert 14:
(1)
14 vs. 31
hole
14
14
1616Cpt S 223. School of EECS, WSU
Percolating Up
Heap Insert: Example
Insert 14:
(1)
14 vs. 31
(2)
hole
14
14
(2)
14 vs. 21
14
1717Cpt S 223. School of EECS, WSU
Percolating Up
Heap Insert: Example
Insert 14:
(1)
14 vs. 31
hole14
(2)
(3)
14 13
Heap order prop
St t
14
(2)
14 vs. 21
14 vs. 13 Structure prop
Path of percolation up
18
p p
18Cpt S 223. School of EECS, WSU
Heap Insert: Implementation
// assume array implementation
void insert( const Comparable &x) {
??
}
19Cpt S 223. School of EECS, WSU
Heap Insert: Implementation
O(log N) timeO(log N) time
2020Cpt S 223. School of EECS, WSU
Heap DeleteMin
 Minimum element is always at the root
 Heap decreases by one in size Heap decreases by one in size
 Move last element into hole at root
l d h l h d Percolate down while heap-order
property not satisfied
21Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
Make this
position
empty
22Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
Copy 31 temporarily
here and move it dow
Is 31 > min(14,16)?
•Yes - swap 31 with min(14,16)
Make this
position
empty
2323Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
31
Is 31 > min(19,21)?
•Yes - swap 31 with min(19,21)
24Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
31
31
Is 31 > min(65,26)?
•Yes - swap 31 with min(65,26)
Is 31 > min(19,21)?
•Yes - swap 31 with min(19,21)
25
Percolating down…
25Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
31
26
Percolating down…
Cpt S 223. School of EECS, WSU
Percolating down…
Heap DeleteMin: Example
31
Heap order prop
Structure prop
27
Structure prop
27Cpt S 223. School of EECS, WSU
Heap DeleteMin:
Implementation
28
O(log N) time
Cpt S 223. School of EECS, WSU
Heap DeleteMin:
Implementation
Percolate
Left child
down
Right child
Pick child to
swap with
29Cpt S 223. School of EECS, WSU
Other Heap Operations
 decreaseKey(p,v)
 Lowers the current value of item p to new priority value v
 Need to percolate upp p
 E.g., promote a job
 increaseKey(p,v)
 Increases the current value of item p to new priority value vp p y
 Need to percolate down
 E.g., demote a job
 remove(p) Run-times for all three functions?(p)
 First, decreaseKey(p,-∞)
 Then, deleteMin
 E.g., abort/cancel a job
O(lg n)
30Cpt S 223. School of EECS, WSU
Improving Heap Insert Time
 What if all N elements are all available
upfront?
 To build a heap with N elements:p
 Default method takes O(N lg N) time
 We will now see a new method called buildHeap()
h ll k ( ) lthat will take O(N) time - i.e., optimal
31Cpt S 223. School of EECS, WSU
Building a Heap
 Construct heap from initial set of N items
 Solution 1
 Perform N inserts
 O(N log2 N) worst-case
 Solution 2 (use buildHeap())
 Randomly populate initial heap with structure
property
 Perform a percolate-down from each internal node
(H[size/2] to H[1])(H[size/2] to H[1])
 To take care of heap order property
32Cpt S 223. School of EECS, WSU
BuildHeap Example
I { 150 80 40 10 70 110 30 120 140 60 50 130 100 20 90 }Input: { 150, 80, 40, 10, 70, 110, 30, 120, 140, 60, 50, 130, 100, 20, 90 }
Leaves are allLeaves are all
valid heaps
(implicitly)
• Arbitrarily assign elements to heap nodes
• Structure property satisfied
• Heap order property violated
So, let us look at each
internal node,
from bottom to top,
and fix if necessary
33
p p p y
• Leaves are all valid heaps (implicit)
and fix if necessary
Cpt S 223. School of EECS, WSU
BuildHeap Example
Swap
Nothing
to do
with left
child
• Randomly initialized heap
34
y p
• Structure property satisfied
• Heap order property violated
• Leaves are all valid heaps (implicit) 34Cpt S 223. School of EECS, WSU
BuildHeap Example Swap
with right
childNothing
to do
Dotted lines show path of percolating down
35
p p g
35Cpt S 223. School of EECS, WSU
Swap with
BuildHeap Example
Nothing
p
right child
& then with 60
Nothing
to do
Dotted lines show path of percolating down
36
p p g
Cpt S 223. School of EECS, WSU
BuildHeap Example
Swap path
Dotted lines show path of percolating down
Final Heap
37
p p g
Cpt S 223. School of EECS, WSU
BuildHeap Implementation
Start with
lowest,
rightmost
i l d
38
internal node
Cpt S 223. School of EECS, WSU
BuildHeap() : Run-time
Analysis
 Run-time = ?
 O(sum of the heights of all the internal nodes)
b h t l t ll thbecause we may have to percolate all the way
down to fix every internal node in the worst-case
 Theorem 6.1 HOW?
 For a perfect binary tree of height h, the sum of
heights of all nodes is 2h+1 – 1 – (h + 1)
Si h l N th f h i ht i O(N) Since h=lg N, then sum of heights is O(N)
 Will be slightly better in practice
Implication: Each insertion costs O(1) amortized time
39Cpt S 223. School of EECS, WSU
40Cpt S 223. School of EECS, WSU
Binary Heap Operations
Worst-case Analysis
 Height of heap is
 insert: O(lg N) for each insert
 N2log
( g )
 In practice, expect less
 buildHeap insert: O(N) for N insertsp ( )
 deleteMin: O(lg N)
 decreaseKey: O(lg N)decreaseKey: O(lg N)
 increaseKey: O(lg N)
 remove: O(lg N) remove: O(lg N)
41Cpt S 223. School of EECS, WSU
Applications
 Operating system scheduling
 Process jobs by priority Process jobs by priority
 Graph algorithms
Find shortest path Find shortest path
 Event simulation
 Instead of checking for events at each time
click, look up next event to happen
42Cpt S 223. School of EECS, WSU
An Application:
The Selection Problem
 Given a list of n elements, find the kth
smallest element
 Algorithm 1:Algorithm 1:
 Sort the list => O(n log n)
 Pick the kth element => O(1)( )
 A better algorithm:
 Use a binary heap (minheap)Use a binary heap (minheap)
43Cpt S 223. School of EECS, WSU
Selection using a MinHeap
 Input: n elements
 Algorithm:
b ildHeap(n) > O(n)1. buildHeap(n) ==> O(n)
2. Perform k deleteMin() operations ==> O(k log n)
3. Report the kth deleteMin output ==> O(1)
Total run-time = O(n + k log n)
If k = O(n/log n) then the run-time becomes O(n)
44Cpt S 223. School of EECS, WSU
Other Types of Heaps
 Binomial Heaps
d H d-Heaps
 Generalization of binary heaps (ie., 2-Heaps)
 Leftist Heaps
 Supports merging of two heaps in o(m+n) time (ie., sub-
linear)
 Skew Heaps
 O(log n) amortized run-time
 Fibonacci Heaps
45Cpt S 223. School of EECS, WSU
Run-time Per Operation
Insert DeleteMin Merge (=H1+H2)
Binary heap  O(log n) worst-case O(log n) O(n)
 O(1) amortized for
buildHeap
Leftist Heap O(log n) O(log n) O(log n)
Skew Heap O(log n) O(log n) O(log n)
Bi i l O(l ) t O(l ) O(l )Binomial
Heap
 O(log n) worst case
 O(1) amortized for
sequence of n inserts
O(log n) O(log n)
Fibonacci Heap O(1) O(log n) O(1)
46Cpt S 223. School of EECS, WSU
Priority Queues in STL
 Uses Binary heap
 Default is MaxHeap
#include <priority_queue>
int main ()p
 Methods
 Push, top, pop,
{
priority_queue<int> Q;
Q.push (10);
cout << Q top ();, p, p p,
empty, clear
cout << Q.top ();
Q.pop ();
}
Calls DeleteMax()
For MinHeap: declare priority_queue as:
priority_queue<int, vector<int>, greater<int>> Q;
47
Refer to Book Chapter 6, Fig 6.57 for an example
Cpt S 223. School of EECS, WSU
Binomial Heaps
48Cpt S 223. School of EECS, WSU
Binomial Heap
 A binomial heap is a forest of heap-ordered
binomial trees, satisfying:
i) Structure property andi) Structure property, and
ii) Heap order property
 A binomial heap is different from binary heap
in that:
 Its structure property is totally different Its structure property is totally different
 Its heap-order property (within each binomial
tree) is the same as in a binary heap
49Cpt S 223. School of EECS, WSU
Note: A binomial tree need not be a binary tree
Definition: A “Binomial Tree” Bk
 A binomial tree of height k is called Bk:
 It has 2k nodes
 The number of nodes at depth d = ( )
k
d
( ) is the form of the co-efficients in binomial theoremk
( ) is the form of the co-efficients in binomial theoremd
d 0 (3
)
Depth: #nodes:B3:
d=0
d=1
d=2
(0 )
(3
1 )
(3
)d=2
d=3
(2 )
(3
3 ) 50Cpt S 223. School of EECS, WSU
What will a Binomial Heap with n=31What will a Binomial Heap with n 31
nodes look like?
 We know that:
i) A binomial heap should be a forest of binomial
trees
ii) Each binomial tree has power of 2 elements
S h bi i l d d?
31 (1 1 1 1 1)
B0B1B2B3B4
 So how many binomial trees do we need?
n = 31 = (1 1 1 1 1)2
51Cpt S 223. School of EECS, WSU
A Bi i l H / 31 dA Binomial Heap w/ n=31 nodes
B0B1B2B3B4
n = 31 = (1 1 1 1 1)2
B0B1B2B3B4
Bi == Bi-1 + Bi-1
1,B2,B3,B4}
B2B3
B1
B0
trees{B0,B1
B2B3
stofbinomialFores
52Cpt S 223. School of EECS, WSU
Binomial Heap Property
 Lemma: There exists a binomial heap for every
positive value of n
 Proof:
 All values of n can be represented in binary representation All values of n can be represented in binary representation
 Have one binomial tree for each power of two with co-efficient
of 1
 Eg., n=10 ==> (1010)2 ==> forest contains {B3, B1} Eg., n 10 > (1010)2 > forest contains {B3, B1}
53Cpt S 223. School of EECS, WSU
Binomial Heaps: Heap-Order
Property
 Each binomial tree should contain the
minimum element at the root of everyy
subtree
 Just like binary heap, except that the tree
h i bi i l t t t ( d there is a binomial tree structure (and not a
complete binary tree)
 The order of elements across binomial
trees is irrelevanttrees is irrelevant
54Cpt S 223. School of EECS, WSU
Definition: Binomial Heaps
 A binomial heap of n nodes is:
 (Structure Property) A forest of binomial trees as dictated by
the binary representation of nthe binary representation of n
 (Heap-Order Property) Each binomial tree is a min-heap or a
hmax-heap
55Cpt S 223. School of EECS, WSU
Binomial Heaps: Examples
Two different heaps:
56Cpt S 223. School of EECS, WSU
Key Properties
 Could there be multiple trees of the same height in a
binomial heap?
no
 What is the upper bound on the number of binomial
trees in a binomial heap of n nodes? ltrees in a binomial heap of n nodes? lg n
 Given n, can we tell (for sure) if Bk exists?
Bk exists if and only if:k y
the kth least significant bit is 1
in the binary representation of n
57Cpt S 223. School of EECS, WSU
An Implementation of a Binomial Heapp p
Example: n=13 == (1101)
Maintain a linked list of
tree pointers (for the forest)
B0B1B2B3B4B5B6B7
Example: n=13 == (1101)2
Shown using the
left child right sibling pointer method
Analogous to a bit-based representation of a
left-child, right-sibling pointer method
g p
binary number n
58Cpt S 223. School of EECS, WSU
Binomial Heap: Operations
 x <= DeleteMin()
 Insert(x)
 Merge(H1, H2)
59Cpt S 223. School of EECS, WSU
DeleteMin()
 Goal: Given a binomial heap, H, find the
minimum and delete it
 Observation: The root of each binomial tree
in H contains its minimum element
 Approach: Therefore, return the minimum of
all the roots (minimums)
 Complexity: O(log n) comparisons
(because there are only O(log n) trees)
60Cpt S 223. School of EECS, WSU
FindMin() & DeleteMin() Example
B0 B2
B3
B1’ B2’B0’
For DeleteMin(): After delete, how to adjust the heap?
New Heap : Merge { B B } & { B ’ B ’ B ’ }New Heap : Merge { B0, B2 } & { B0 , B1 , B2 }
61Cpt S 223. School of EECS, WSU
Insert(x) in Binomial Heap
 Goal: To insert a new element x into a
binomial heap Hbinomial heap H
 Observation:
Element x can be viewed as a single Element x can be viewed as a single
element binomial heap
 => Insert (H x) == Merge(H, {x}) > Insert (H,x) Merge(H, {x})
So, if we decide how to do merge we will automatically
figure out how to implement both insert() and deleteMin()
62Cpt S 223. School of EECS, WSU
Merge(H1,H2)
 Let n1 be the number of nodes in H1
 Let n2 be the number of nodes in H2
 Therefore the new heap is going to have n + n Therefore, the new heap is going to have n1 + n2
nodes
 Assume n = n1 + n2
 Logic:
 Merge trees of same height, starting from lowest height
treestrees
 If only one tree of a given height, then just copy that
 Otherwise, need to do carryover (just like adding two binary
numbers)
63Cpt S 223. School of EECS, WSU
Idea: merge tree of same heights
Merge: Example
+
B0 B1 B2
13
? ? 64Cpt S 223. School of EECS, WSU
How to Merge Two Binomial
Trees of the Same Height?
+
B2:
B2: B3:
Simply compare the roots
Note: Merge is defined for only binomial trees with the same height 65Cpt S 223. School of EECS, WSU
Merge(H H ) exampleMerge(H1,H2) example
carryover
+
13 14
16
?
26 16
26
66Cpt S 223. School of EECS, WSU
How to Merge more than twog
binomial trees of the same height?
 Merging more than 2 binomial trees of
the same height could generate carry-g g y
overs
+ +
14
?+
26 16
26
?
Merge any two and leave the third as carry-overMerge any two and leave the third as carry over
67Cpt S 223. School of EECS, WSU
Input:
+
Merge(H1,H2) : Example
Output:
There are t o other possible ans ersThere are two other possible answers
Merge cost log(max{n1 n2}) = O(log n) comparisonsMerge cost log(max{n1,n2}) = O(log n) comparisons
68Cpt S 223. School of EECS, WSU
Run-time Complexities
 Merge takes O(log n) comparisons
 Corollary: Corollary:
 Insert and DeleteMin also take O(log n)
 It can be further proved that an uninterrupted sequence of m It can be further proved that an uninterrupted sequence of m
Insert operations takes only O(m) time per operation, implying
O(1) amortize time per insert
 Proof Hint:
 For each insertion, if i is the least significant bit position with a 0, then
number of comparisons required to do the next insert is i+1
 If you count the #bit flips for each insert, going from insert of the first
element to the insert of the last (nth) element, then
> amortized run time of O(1) per insert10010111
affected
unaffected
=> amortized run-time of O(1) per insert10010111
1
--------------
10011000
69Cpt S 223. School of EECS, WSU
Binomial Queue Run-time
Summary
 Insert
 O(lg n) worst-case
 O(1) amortized time if insertion is done in an
uninterrupted sequence (i.e., without being
intervened by deleteMins)
 DeleteMin, FindMin
 O(lg n) worst-case
 Merge
 O(lg n) worst-case
70Cpt S 223. School of EECS, WSU
Run-time Per Operation
Insert DeleteMin Merge (=H1+H2)
Binary heap  O(log n) worst-case O(log n) O(n)
 O(1) amortized for
buildHeap
Leftist Heap O(log n) O(log n) O(log n)
Skew Heap O(log n) O(log n) O(log n)
Bi i l O(l ) t O(l ) O(l )Binomial
Heap
 O(log n) worst case
 O(1) amortized for
sequence of n inserts
O(log n) O(log n)
Fibonacci Heap O(1) O(log n) O(1)
71Cpt S 223. School of EECS, WSU
Summary
 Priority queues maintain the minimum
or maximum element of a setor maximum element of a set
 Support O(log N) operations worst-case
insert deleteMin merge insert, deleteMin, merge
 Many applications in support of other
l ithalgorithms
72Cpt S 223. School of EECS, WSU

More Related Content

What's hot

INSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMINSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMKamran Ashraf
 
BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC  COMPUTER  ORGANIZATION  AND  DESIGNBASIC  COMPUTER  ORGANIZATION  AND  DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGN
Dr. Ajay Kumar Singh
 
22CS201 COA
22CS201 COA22CS201 COA
22CS201 COA
Kathirvel Ayyaswamy
 
I/O Organization
I/O OrganizationI/O Organization
I/O Organization
Dhaval Bagal
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
RITULDE
 
REGISTER TRANSFER AND MICRO OPERATIONS
REGISTER TRANSFER AND MICRO OPERATIONSREGISTER TRANSFER AND MICRO OPERATIONS
REGISTER TRANSFER AND MICRO OPERATIONS
Anonymous Red
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria myrajendra
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
Gaditek
 
Ch 04 (Siklus Instruksi dan Interrupt)
Ch 04 (Siklus Instruksi dan Interrupt)Ch 04 (Siklus Instruksi dan Interrupt)
Ch 04 (Siklus Instruksi dan Interrupt)
Tri Sugihartono
 
Computer organization and architecture
Computer organization and architectureComputer organization and architecture
Computer organization and architectureSubesh Kumar Yadav
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
Mazin Alwaaly
 
Minggu ketiga
Minggu ketigaMinggu ketiga
Minggu ketiga
Daudi Lazarus
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
Archana Gopinath
 
Control unit
Control unitControl unit
Control unit
Syed Zaid Irshad
 
process control block
process control blockprocess control block
process control block
Vikas SHRIVASTAVA
 
Input Output Operations
Input Output OperationsInput Output Operations
Input Output Operationskdisthere
 
Arquitectura de Computadores: Generaciones de Computadores
Arquitectura de Computadores: Generaciones de ComputadoresArquitectura de Computadores: Generaciones de Computadores
Arquitectura de Computadores: Generaciones de Computadores
Luis Fernando Aguas Bucheli
 
Pipelining
PipeliningPipelining
Pipelining
Shubham Bammi
 

What's hot (20)

INSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISMINSTRUCTION LEVEL PARALLALISM
INSTRUCTION LEVEL PARALLALISM
 
BASIC COMPUTER ORGANIZATION AND DESIGN
BASIC  COMPUTER  ORGANIZATION  AND  DESIGNBASIC  COMPUTER  ORGANIZATION  AND  DESIGN
BASIC COMPUTER ORGANIZATION AND DESIGN
 
22CS201 COA
22CS201 COA22CS201 COA
22CS201 COA
 
I/O Organization
I/O OrganizationI/O Organization
I/O Organization
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
REGISTER TRANSFER AND MICRO OPERATIONS
REGISTER TRANSFER AND MICRO OPERATIONSREGISTER TRANSFER AND MICRO OPERATIONS
REGISTER TRANSFER AND MICRO OPERATIONS
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
 
Ch 04 (Siklus Instruksi dan Interrupt)
Ch 04 (Siklus Instruksi dan Interrupt)Ch 04 (Siklus Instruksi dan Interrupt)
Ch 04 (Siklus Instruksi dan Interrupt)
 
Computer organization and architecture
Computer organization and architectureComputer organization and architecture
Computer organization and architecture
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
 
Penjadwalan.pdf
Penjadwalan.pdfPenjadwalan.pdf
Penjadwalan.pdf
 
Minggu ketiga
Minggu ketigaMinggu ketiga
Minggu ketiga
 
Language for specifying lexical Analyzer
Language for specifying lexical AnalyzerLanguage for specifying lexical Analyzer
Language for specifying lexical Analyzer
 
Control unit
Control unitControl unit
Control unit
 
process control block
process control blockprocess control block
process control block
 
Input Output Operations
Input Output OperationsInput Output Operations
Input Output Operations
 
Arquitectura de Computadores: Generaciones de Computadores
Arquitectura de Computadores: Generaciones de ComputadoresArquitectura de Computadores: Generaciones de Computadores
Arquitectura de Computadores: Generaciones de Computadores
 
Pipelining
PipeliningPipelining
Pipelining
 

Viewers also liked

Characterization of lignins by Py/GC/MS
Characterization of lignins by Py/GC/MSCharacterization of lignins by Py/GC/MS
Characterization of lignins by Py/GC/MS
Michal Jablonsky
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sorting
heshekik
 
B-Tree
B-TreeB-Tree
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
ecomputernotes
 
B Trees
B TreesB Trees
Priority queues
Priority queuesPriority queues
Priority queues
Yeela Mehroz
 
LigniMatch_technical_report
LigniMatch_technical_reportLigniMatch_technical_report
LigniMatch_technical_reportMaria Svane
 
Solid liquid separation alternatives for manure handling and treatment
Solid liquid separation alternatives for manure handling and treatmentSolid liquid separation alternatives for manure handling and treatment
Solid liquid separation alternatives for manure handling and treatment
LPE Learning Center
 
Uses of lignin as replacement for cement
Uses of lignin as replacement for cementUses of lignin as replacement for cement
Uses of lignin as replacement for cement
ARIVU SUDAR
 
Process for Recovery of phosphorus (P) from solid manure
Process for Recovery of phosphorus (P) from solid manureProcess for Recovery of phosphorus (P) from solid manure
Process for Recovery of phosphorus (P) from solid manure
LPE Learning Center
 
Uranium Enrichment Technology II
Uranium Enrichment Technology IIUranium Enrichment Technology II
Uranium Enrichment Technology IIcarolala
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queueTareq Hasan
 
Material Bonding Powerpoint
Material Bonding PowerpointMaterial Bonding Powerpoint
Material Bonding PowerpointJutka Czirok
 

Viewers also liked (20)

Heaps
HeapsHeaps
Heaps
 
Heaps
HeapsHeaps
Heaps
 
Characterization of lignins by Py/GC/MS
Characterization of lignins by Py/GC/MSCharacterization of lignins by Py/GC/MS
Characterization of lignins by Py/GC/MS
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Priority queues and heap sorting
Priority queues and heap sortingPriority queues and heap sorting
Priority queues and heap sorting
 
B-Tree
B-TreeB-Tree
B-Tree
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
 
Priority queue
Priority queuePriority queue
Priority queue
 
B Trees
B TreesB Trees
B Trees
 
Priority queues
Priority queuesPriority queues
Priority queues
 
chapter - 6.ppt
chapter - 6.pptchapter - 6.ppt
chapter - 6.ppt
 
LigniMatch_technical_report
LigniMatch_technical_reportLigniMatch_technical_report
LigniMatch_technical_report
 
Solid liquid separation alternatives for manure handling and treatment
Solid liquid separation alternatives for manure handling and treatmentSolid liquid separation alternatives for manure handling and treatment
Solid liquid separation alternatives for manure handling and treatment
 
Uses of lignin as replacement for cement
Uses of lignin as replacement for cementUses of lignin as replacement for cement
Uses of lignin as replacement for cement
 
B tree
B treeB tree
B tree
 
Process for Recovery of phosphorus (P) from solid manure
Process for Recovery of phosphorus (P) from solid manureProcess for Recovery of phosphorus (P) from solid manure
Process for Recovery of phosphorus (P) from solid manure
 
Uranium Enrichment Technology II
Uranium Enrichment Technology IIUranium Enrichment Technology II
Uranium Enrichment Technology II
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Material Bonding Powerpoint
Material Bonding PowerpointMaterial Bonding Powerpoint
Material Bonding Powerpoint
 

Similar to Heaps

03-data-structures.pdf
03-data-structures.pdf03-data-structures.pdf
03-data-structures.pdf
Nash229987
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
Donal Fellows
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for Java
Lisa Hua
 
Dsoop (co 221) 1
Dsoop (co 221) 1Dsoop (co 221) 1
Dsoop (co 221) 1
Puja Koch
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
chandsek666
 
Ee693 sept2014quizgt1
Ee693 sept2014quizgt1Ee693 sept2014quizgt1
Ee693 sept2014quizgt1
Gopi Saiteja
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
Chandan Kumar
 
Week2-stacks-queues.pptx
Week2-stacks-queues.pptxWeek2-stacks-queues.pptx
Week2-stacks-queues.pptx
VandanaBharti21
 
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
Alex Pruden
 
Bellmon Ford Algorithm
Bellmon Ford AlgorithmBellmon Ford Algorithm
Bellmon Ford Algorithm
69RishabhPandey
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
RTEFGDFGJU
 
Graph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph AlgorithmsGraph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph Algorithms
htttuneti
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
PrabhakarSingh646829
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
Ssankett Negi
 
3.01.Lists.pptx
3.01.Lists.pptx3.01.Lists.pptx
3.01.Lists.pptx
SURESHM22PHD10013
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
Senthil Kumar
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
Ahmed BESBES
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
Mahmoud Samir Fayed
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
Jonas Follesø
 

Similar to Heaps (20)

03-data-structures.pdf
03-data-structures.pdf03-data-structures.pdf
03-data-structures.pdf
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for Java
 
Dsoop (co 221) 1
Dsoop (co 221) 1Dsoop (co 221) 1
Dsoop (co 221) 1
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Ee693 sept2014quizgt1
Ee693 sept2014quizgt1Ee693 sept2014quizgt1
Ee693 sept2014quizgt1
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
 
Week2-stacks-queues.pptx
Week2-stacks-queues.pptxWeek2-stacks-queues.pptx
Week2-stacks-queues.pptx
 
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
zkStudyClub: PLONKUP & Reinforced Concrete [Luke Pearson, Joshua Fitzgerald, ...
 
Bellmon Ford Algorithm
Bellmon Ford AlgorithmBellmon Ford Algorithm
Bellmon Ford Algorithm
 
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdfreservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
reservoir-modeling-using-matlab-the-matalb-reservoir-simulation-toolbox-mrst.pdf
 
Graph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph AlgorithmsGraph Algorithms Graph Algorithms Graph Algorithms
Graph Algorithms Graph Algorithms Graph Algorithms
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
3.01.Lists.pptx
3.01.Lists.pptx3.01.Lists.pptx
3.01.Lists.pptx
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
Introduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from ScratchIntroduction to Neural Networks and Deep Learning from Scratch
Introduction to Neural Networks and Deep Learning from Scratch
 
The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181The Ring programming language version 1.5.2 book - Part 34 of 181
The Ring programming language version 1.5.2 book - Part 34 of 181
 
Why learn new programming languages
Why learn new programming languagesWhy learn new programming languages
Why learn new programming languages
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
IIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
IIUM
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
IIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
IIUM
 
Group p1
Group p1Group p1
Group p1
IIUM
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
IIUM
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
IIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
IIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
IIUM
 
Report format
Report formatReport format
Report format
IIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
IIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
IIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
IIUM
 
Vpn
VpnVpn
Vpn
IIUM
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 
Vpn
VpnVpn
Vpn
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 

Heaps

  • 1. Priority Queues (Heaps)Priority Queues (Heaps) 111111Cpt S 223. School of EECS, WSU
  • 2. Motivation  Queues are a standard mechanism for ordering tasks on a first-come, first-served basis  However, some tasks may be more important or timely than others (higher priority)  Priority queues Priority queues  Store tasks using a partial ordering based on priority  Ensure highest priority task at head of queue  Heaps are the underlying data structure of priority queues 22222Cpt S 223. School of EECS, WSU
  • 3. Priority Queues: Specification  Main operations  insert (i.e., enqueue) D i i t Dynamic insert  specification of a priority level (0-high, 1,2.. Low)  deleteMin (i.e., dequeue)  Finds the current minimum element (read: “highest priority”) in the queue, deletes it from the queue, and returns it  Performance goal is for operations to be “fast” 3Cpt S 223. School of EECS, WSU
  • 4. Using priority queues 5 3 10 13 19 4 13 8 2211 insert() deleteMin() 2 Dequeues the next element with the highest prioritywith the highest priority 4Cpt S 223. School of EECS, WSU
  • 5. Can we build a data structure better suited to store and retrieve priorities? Simple Implementations  Unordered linked list  O(1) insert  O(n) deleteMin 5 2 10 3…  O(n) deleteMin  Ordered linked list  O(n) insert O(1) d l t Mi 2 3 5 10…  O(1) deleteMin  Ordered array  O(lg n + n) insert 2 3 5 … 10  O(n) deleteMin  Balanced BST  O(log2n) insert and deleteMin O(log2n) insert and deleteMin 55Cpt S 223. School of EECS, WSU
  • 6. Bi HBinary Heap A priority queue data structure 6Cpt S 223. School of EECS, WSU
  • 7. Binary Heap  A binary heap is a binary tree with two propertiesproperties  Structure property  Heap-order property Heap order property 7Cpt S 223. School of EECS, WSU
  • 8. Structure Property  A binary heap is a complete binary tree  Each level (except possibly the bottom most level)( p p y ) is completely filled  The bottom most level may be partially filled (f l ft t i ht)(from left to right)  Height of a complete binary tree with N elements is  N2log 88Cpt S 223. School of EECS, WSU
  • 9. Structure property Binary Heap Example N=10 Every level (except last) saturated Array representation: 9Cpt S 223. School of EECS, WSU
  • 10. Heap-order Property  Heap-order property (for a “MinHeap”)  For every node X key(parent(X)) ≤ key(X) For every node X, key(parent(X)) ≤ key(X)  Except root node, which has no parent Thus minimum key always at root Thus, minimum key always at root  Alternatively, for a “MaxHeap”, always keep the maximum key at the rootkeep the maximum key at the root  Insert and deleteMin must maintain heap order propertyheap-order property 10Cpt S 223. School of EECS, WSU
  • 11. Heap Order Property Minimum element            Duplicates are allowed     Duplicates are allowed  No order implied for elements which do not share ancestor-descendant relationshipshare ancestor descendant relationship 11Cpt S 223. School of EECS, WSU
  • 12. Implementing Complete Binary Trees as Arrays  Given element at position i in the array  Left child(i) = at position 2i Left child(i) at position 2i  Right child(i) = at position 2i + 1  Parent(i) = at position  2/i Parent(i) = at position  2/i 2i 2i + 1 i i/2 12 i/2 Cpt S 223. School of EECS, WSU
  • 13. Just finds the Min insert Just finds the Min without deleting it deleteMin Note: a general delete() function is not as important for heaps but could be implemented Stores the heap as a vector Fix heap after 13 p deleteMin Cpt S 223. School of EECS, WSU
  • 14. Heap Insert  Insert new element into the heap at the next available slot (“hole”)next available slot ( hole )  According to maintaining a complete binary tree  Then, “percolate” the element up the heap while heap-order property notheap while heap order property not satisfied 14Cpt S 223. School of EECS, WSU
  • 15. Percolating Up Heap Insert: Example Insert 14: hole14 15Cpt S 223. School of EECS, WSU
  • 16. Percolating Up Heap Insert: Example Insert 14: (1) 14 vs. 31 hole 14 14 1616Cpt S 223. School of EECS, WSU
  • 17. Percolating Up Heap Insert: Example Insert 14: (1) 14 vs. 31 (2) hole 14 14 (2) 14 vs. 21 14 1717Cpt S 223. School of EECS, WSU
  • 18. Percolating Up Heap Insert: Example Insert 14: (1) 14 vs. 31 hole14 (2) (3) 14 13 Heap order prop St t 14 (2) 14 vs. 21 14 vs. 13 Structure prop Path of percolation up 18 p p 18Cpt S 223. School of EECS, WSU
  • 19. Heap Insert: Implementation // assume array implementation void insert( const Comparable &x) { ?? } 19Cpt S 223. School of EECS, WSU
  • 20. Heap Insert: Implementation O(log N) timeO(log N) time 2020Cpt S 223. School of EECS, WSU
  • 21. Heap DeleteMin  Minimum element is always at the root  Heap decreases by one in size Heap decreases by one in size  Move last element into hole at root l d h l h d Percolate down while heap-order property not satisfied 21Cpt S 223. School of EECS, WSU
  • 22. Percolating down… Heap DeleteMin: Example Make this position empty 22Cpt S 223. School of EECS, WSU
  • 23. Percolating down… Heap DeleteMin: Example Copy 31 temporarily here and move it dow Is 31 > min(14,16)? •Yes - swap 31 with min(14,16) Make this position empty 2323Cpt S 223. School of EECS, WSU
  • 24. Percolating down… Heap DeleteMin: Example 31 Is 31 > min(19,21)? •Yes - swap 31 with min(19,21) 24Cpt S 223. School of EECS, WSU
  • 25. Percolating down… Heap DeleteMin: Example 31 31 Is 31 > min(65,26)? •Yes - swap 31 with min(65,26) Is 31 > min(19,21)? •Yes - swap 31 with min(19,21) 25 Percolating down… 25Cpt S 223. School of EECS, WSU
  • 26. Percolating down… Heap DeleteMin: Example 31 26 Percolating down… Cpt S 223. School of EECS, WSU
  • 27. Percolating down… Heap DeleteMin: Example 31 Heap order prop Structure prop 27 Structure prop 27Cpt S 223. School of EECS, WSU
  • 28. Heap DeleteMin: Implementation 28 O(log N) time Cpt S 223. School of EECS, WSU
  • 29. Heap DeleteMin: Implementation Percolate Left child down Right child Pick child to swap with 29Cpt S 223. School of EECS, WSU
  • 30. Other Heap Operations  decreaseKey(p,v)  Lowers the current value of item p to new priority value v  Need to percolate upp p  E.g., promote a job  increaseKey(p,v)  Increases the current value of item p to new priority value vp p y  Need to percolate down  E.g., demote a job  remove(p) Run-times for all three functions?(p)  First, decreaseKey(p,-∞)  Then, deleteMin  E.g., abort/cancel a job O(lg n) 30Cpt S 223. School of EECS, WSU
  • 31. Improving Heap Insert Time  What if all N elements are all available upfront?  To build a heap with N elements:p  Default method takes O(N lg N) time  We will now see a new method called buildHeap() h ll k ( ) lthat will take O(N) time - i.e., optimal 31Cpt S 223. School of EECS, WSU
  • 32. Building a Heap  Construct heap from initial set of N items  Solution 1  Perform N inserts  O(N log2 N) worst-case  Solution 2 (use buildHeap())  Randomly populate initial heap with structure property  Perform a percolate-down from each internal node (H[size/2] to H[1])(H[size/2] to H[1])  To take care of heap order property 32Cpt S 223. School of EECS, WSU
  • 33. BuildHeap Example I { 150 80 40 10 70 110 30 120 140 60 50 130 100 20 90 }Input: { 150, 80, 40, 10, 70, 110, 30, 120, 140, 60, 50, 130, 100, 20, 90 } Leaves are allLeaves are all valid heaps (implicitly) • Arbitrarily assign elements to heap nodes • Structure property satisfied • Heap order property violated So, let us look at each internal node, from bottom to top, and fix if necessary 33 p p p y • Leaves are all valid heaps (implicit) and fix if necessary Cpt S 223. School of EECS, WSU
  • 34. BuildHeap Example Swap Nothing to do with left child • Randomly initialized heap 34 y p • Structure property satisfied • Heap order property violated • Leaves are all valid heaps (implicit) 34Cpt S 223. School of EECS, WSU
  • 35. BuildHeap Example Swap with right childNothing to do Dotted lines show path of percolating down 35 p p g 35Cpt S 223. School of EECS, WSU
  • 36. Swap with BuildHeap Example Nothing p right child & then with 60 Nothing to do Dotted lines show path of percolating down 36 p p g Cpt S 223. School of EECS, WSU
  • 37. BuildHeap Example Swap path Dotted lines show path of percolating down Final Heap 37 p p g Cpt S 223. School of EECS, WSU
  • 38. BuildHeap Implementation Start with lowest, rightmost i l d 38 internal node Cpt S 223. School of EECS, WSU
  • 39. BuildHeap() : Run-time Analysis  Run-time = ?  O(sum of the heights of all the internal nodes) b h t l t ll thbecause we may have to percolate all the way down to fix every internal node in the worst-case  Theorem 6.1 HOW?  For a perfect binary tree of height h, the sum of heights of all nodes is 2h+1 – 1 – (h + 1) Si h l N th f h i ht i O(N) Since h=lg N, then sum of heights is O(N)  Will be slightly better in practice Implication: Each insertion costs O(1) amortized time 39Cpt S 223. School of EECS, WSU
  • 40. 40Cpt S 223. School of EECS, WSU
  • 41. Binary Heap Operations Worst-case Analysis  Height of heap is  insert: O(lg N) for each insert  N2log ( g )  In practice, expect less  buildHeap insert: O(N) for N insertsp ( )  deleteMin: O(lg N)  decreaseKey: O(lg N)decreaseKey: O(lg N)  increaseKey: O(lg N)  remove: O(lg N) remove: O(lg N) 41Cpt S 223. School of EECS, WSU
  • 42. Applications  Operating system scheduling  Process jobs by priority Process jobs by priority  Graph algorithms Find shortest path Find shortest path  Event simulation  Instead of checking for events at each time click, look up next event to happen 42Cpt S 223. School of EECS, WSU
  • 43. An Application: The Selection Problem  Given a list of n elements, find the kth smallest element  Algorithm 1:Algorithm 1:  Sort the list => O(n log n)  Pick the kth element => O(1)( )  A better algorithm:  Use a binary heap (minheap)Use a binary heap (minheap) 43Cpt S 223. School of EECS, WSU
  • 44. Selection using a MinHeap  Input: n elements  Algorithm: b ildHeap(n) > O(n)1. buildHeap(n) ==> O(n) 2. Perform k deleteMin() operations ==> O(k log n) 3. Report the kth deleteMin output ==> O(1) Total run-time = O(n + k log n) If k = O(n/log n) then the run-time becomes O(n) 44Cpt S 223. School of EECS, WSU
  • 45. Other Types of Heaps  Binomial Heaps d H d-Heaps  Generalization of binary heaps (ie., 2-Heaps)  Leftist Heaps  Supports merging of two heaps in o(m+n) time (ie., sub- linear)  Skew Heaps  O(log n) amortized run-time  Fibonacci Heaps 45Cpt S 223. School of EECS, WSU
  • 46. Run-time Per Operation Insert DeleteMin Merge (=H1+H2) Binary heap  O(log n) worst-case O(log n) O(n)  O(1) amortized for buildHeap Leftist Heap O(log n) O(log n) O(log n) Skew Heap O(log n) O(log n) O(log n) Bi i l O(l ) t O(l ) O(l )Binomial Heap  O(log n) worst case  O(1) amortized for sequence of n inserts O(log n) O(log n) Fibonacci Heap O(1) O(log n) O(1) 46Cpt S 223. School of EECS, WSU
  • 47. Priority Queues in STL  Uses Binary heap  Default is MaxHeap #include <priority_queue> int main ()p  Methods  Push, top, pop, { priority_queue<int> Q; Q.push (10); cout << Q top ();, p, p p, empty, clear cout << Q.top (); Q.pop (); } Calls DeleteMax() For MinHeap: declare priority_queue as: priority_queue<int, vector<int>, greater<int>> Q; 47 Refer to Book Chapter 6, Fig 6.57 for an example Cpt S 223. School of EECS, WSU
  • 48. Binomial Heaps 48Cpt S 223. School of EECS, WSU
  • 49. Binomial Heap  A binomial heap is a forest of heap-ordered binomial trees, satisfying: i) Structure property andi) Structure property, and ii) Heap order property  A binomial heap is different from binary heap in that:  Its structure property is totally different Its structure property is totally different  Its heap-order property (within each binomial tree) is the same as in a binary heap 49Cpt S 223. School of EECS, WSU
  • 50. Note: A binomial tree need not be a binary tree Definition: A “Binomial Tree” Bk  A binomial tree of height k is called Bk:  It has 2k nodes  The number of nodes at depth d = ( ) k d ( ) is the form of the co-efficients in binomial theoremk ( ) is the form of the co-efficients in binomial theoremd d 0 (3 ) Depth: #nodes:B3: d=0 d=1 d=2 (0 ) (3 1 ) (3 )d=2 d=3 (2 ) (3 3 ) 50Cpt S 223. School of EECS, WSU
  • 51. What will a Binomial Heap with n=31What will a Binomial Heap with n 31 nodes look like?  We know that: i) A binomial heap should be a forest of binomial trees ii) Each binomial tree has power of 2 elements S h bi i l d d? 31 (1 1 1 1 1) B0B1B2B3B4  So how many binomial trees do we need? n = 31 = (1 1 1 1 1)2 51Cpt S 223. School of EECS, WSU
  • 52. A Bi i l H / 31 dA Binomial Heap w/ n=31 nodes B0B1B2B3B4 n = 31 = (1 1 1 1 1)2 B0B1B2B3B4 Bi == Bi-1 + Bi-1 1,B2,B3,B4} B2B3 B1 B0 trees{B0,B1 B2B3 stofbinomialFores 52Cpt S 223. School of EECS, WSU
  • 53. Binomial Heap Property  Lemma: There exists a binomial heap for every positive value of n  Proof:  All values of n can be represented in binary representation All values of n can be represented in binary representation  Have one binomial tree for each power of two with co-efficient of 1  Eg., n=10 ==> (1010)2 ==> forest contains {B3, B1} Eg., n 10 > (1010)2 > forest contains {B3, B1} 53Cpt S 223. School of EECS, WSU
  • 54. Binomial Heaps: Heap-Order Property  Each binomial tree should contain the minimum element at the root of everyy subtree  Just like binary heap, except that the tree h i bi i l t t t ( d there is a binomial tree structure (and not a complete binary tree)  The order of elements across binomial trees is irrelevanttrees is irrelevant 54Cpt S 223. School of EECS, WSU
  • 55. Definition: Binomial Heaps  A binomial heap of n nodes is:  (Structure Property) A forest of binomial trees as dictated by the binary representation of nthe binary representation of n  (Heap-Order Property) Each binomial tree is a min-heap or a hmax-heap 55Cpt S 223. School of EECS, WSU
  • 56. Binomial Heaps: Examples Two different heaps: 56Cpt S 223. School of EECS, WSU
  • 57. Key Properties  Could there be multiple trees of the same height in a binomial heap? no  What is the upper bound on the number of binomial trees in a binomial heap of n nodes? ltrees in a binomial heap of n nodes? lg n  Given n, can we tell (for sure) if Bk exists? Bk exists if and only if:k y the kth least significant bit is 1 in the binary representation of n 57Cpt S 223. School of EECS, WSU
  • 58. An Implementation of a Binomial Heapp p Example: n=13 == (1101) Maintain a linked list of tree pointers (for the forest) B0B1B2B3B4B5B6B7 Example: n=13 == (1101)2 Shown using the left child right sibling pointer method Analogous to a bit-based representation of a left-child, right-sibling pointer method g p binary number n 58Cpt S 223. School of EECS, WSU
  • 59. Binomial Heap: Operations  x <= DeleteMin()  Insert(x)  Merge(H1, H2) 59Cpt S 223. School of EECS, WSU
  • 60. DeleteMin()  Goal: Given a binomial heap, H, find the minimum and delete it  Observation: The root of each binomial tree in H contains its minimum element  Approach: Therefore, return the minimum of all the roots (minimums)  Complexity: O(log n) comparisons (because there are only O(log n) trees) 60Cpt S 223. School of EECS, WSU
  • 61. FindMin() & DeleteMin() Example B0 B2 B3 B1’ B2’B0’ For DeleteMin(): After delete, how to adjust the heap? New Heap : Merge { B B } & { B ’ B ’ B ’ }New Heap : Merge { B0, B2 } & { B0 , B1 , B2 } 61Cpt S 223. School of EECS, WSU
  • 62. Insert(x) in Binomial Heap  Goal: To insert a new element x into a binomial heap Hbinomial heap H  Observation: Element x can be viewed as a single Element x can be viewed as a single element binomial heap  => Insert (H x) == Merge(H, {x}) > Insert (H,x) Merge(H, {x}) So, if we decide how to do merge we will automatically figure out how to implement both insert() and deleteMin() 62Cpt S 223. School of EECS, WSU
  • 63. Merge(H1,H2)  Let n1 be the number of nodes in H1  Let n2 be the number of nodes in H2  Therefore the new heap is going to have n + n Therefore, the new heap is going to have n1 + n2 nodes  Assume n = n1 + n2  Logic:  Merge trees of same height, starting from lowest height treestrees  If only one tree of a given height, then just copy that  Otherwise, need to do carryover (just like adding two binary numbers) 63Cpt S 223. School of EECS, WSU
  • 64. Idea: merge tree of same heights Merge: Example + B0 B1 B2 13 ? ? 64Cpt S 223. School of EECS, WSU
  • 65. How to Merge Two Binomial Trees of the Same Height? + B2: B2: B3: Simply compare the roots Note: Merge is defined for only binomial trees with the same height 65Cpt S 223. School of EECS, WSU
  • 66. Merge(H H ) exampleMerge(H1,H2) example carryover + 13 14 16 ? 26 16 26 66Cpt S 223. School of EECS, WSU
  • 67. How to Merge more than twog binomial trees of the same height?  Merging more than 2 binomial trees of the same height could generate carry-g g y overs + + 14 ?+ 26 16 26 ? Merge any two and leave the third as carry-overMerge any two and leave the third as carry over 67Cpt S 223. School of EECS, WSU
  • 68. Input: + Merge(H1,H2) : Example Output: There are t o other possible ans ersThere are two other possible answers Merge cost log(max{n1 n2}) = O(log n) comparisonsMerge cost log(max{n1,n2}) = O(log n) comparisons 68Cpt S 223. School of EECS, WSU
  • 69. Run-time Complexities  Merge takes O(log n) comparisons  Corollary: Corollary:  Insert and DeleteMin also take O(log n)  It can be further proved that an uninterrupted sequence of m It can be further proved that an uninterrupted sequence of m Insert operations takes only O(m) time per operation, implying O(1) amortize time per insert  Proof Hint:  For each insertion, if i is the least significant bit position with a 0, then number of comparisons required to do the next insert is i+1  If you count the #bit flips for each insert, going from insert of the first element to the insert of the last (nth) element, then > amortized run time of O(1) per insert10010111 affected unaffected => amortized run-time of O(1) per insert10010111 1 -------------- 10011000 69Cpt S 223. School of EECS, WSU
  • 70. Binomial Queue Run-time Summary  Insert  O(lg n) worst-case  O(1) amortized time if insertion is done in an uninterrupted sequence (i.e., without being intervened by deleteMins)  DeleteMin, FindMin  O(lg n) worst-case  Merge  O(lg n) worst-case 70Cpt S 223. School of EECS, WSU
  • 71. Run-time Per Operation Insert DeleteMin Merge (=H1+H2) Binary heap  O(log n) worst-case O(log n) O(n)  O(1) amortized for buildHeap Leftist Heap O(log n) O(log n) O(log n) Skew Heap O(log n) O(log n) O(log n) Bi i l O(l ) t O(l ) O(l )Binomial Heap  O(log n) worst case  O(1) amortized for sequence of n inserts O(log n) O(log n) Fibonacci Heap O(1) O(log n) O(1) 71Cpt S 223. School of EECS, WSU
  • 72. Summary  Priority queues maintain the minimum or maximum element of a setor maximum element of a set  Support O(log N) operations worst-case insert deleteMin merge insert, deleteMin, merge  Many applications in support of other l ithalgorithms 72Cpt S 223. School of EECS, WSU