Functional Blocks of a Computer: Functional blocks and its operations. Instruction set architecture of a CPU - registers, instruction execution cycle, Data path, RTL interpretation of
instructions, instruction set. Performance metrics. Addressing modes. Data Representation:
Signed number representation, fixed and floating point representations, character representation.
Computer arithmetic - integer addition and subtraction, ripple carry adder, carry look-ahead
adder, etc. multiplication - shift-and add, Booth multiplier, carry save multiplier, etc. Division
restoring and non-restoring techniques, floating point arithmetic.
The control unit (CU) is a component of a computer's central processing unit (CPU) that directs the operation of the processor. It tells the computer's memory, arithmetic/logic unit and input and output devices how to respond to a program's instructions.
Functional Blocks of a Computer: Functional blocks and its operations. Instruction set architecture of a CPU - registers, instruction execution cycle, Data path, RTL interpretation of
instructions, instruction set. Performance metrics. Addressing modes. Data Representation:
Signed number representation, fixed and floating point representations, character representation.
Computer arithmetic - integer addition and subtraction, ripple carry adder, carry look-ahead
adder, etc. multiplication - shift-and add, Booth multiplier, carry save multiplier, etc. Division
restoring and non-restoring techniques, floating point arithmetic.
The control unit (CU) is a component of a computer's central processing unit (CPU) that directs the operation of the processor. It tells the computer's memory, arithmetic/logic unit and input and output devices how to respond to a program's instructions.
Lignin is a complex macromolecule structure found in plants. Through appropriate degradation of lignin it is possible to prepare chemicals with an added value. Therefore, it is important to use the best possible way for lignin degradation. Powerful method for characterization of the degradation is thermal analysis and the combination of pyrolysis with gas chromatography coupled with mass spectrometry. In this work, different commercial and prepared lignins were investigated.
Insert works in constant time for either end of a linked list. Remove works in constant time only. Seems best that head of the linked list be the front of the queue so that all removes will be from the front. Inserts will be at the end of the list
Solid liquid separation alternatives for manure handling and treatmentLPE Learning Center
For more: http://www.extension.org/67673 Solid-liquid separation of animal manures and other agricultural products can be an integral part of a livestock operation ranging from improved facility performance to enhanced nutrient management. A document entitled “Solid-Liquid Separation Alternatives for Manure Handling and Treatment” is being created through work by Clemson University and funding from USDA-Natural Resources Conservation Service. The purpose of this document is to assist in solid-liquid separation technology selection, evaluation of separation performance, and quantifying the impact of solid-liquid separation on manure management. This presentation will provide an outline of this document including methods of solid-liquid separation, influence of manure characteristics and handling methods, fundamentals of solid-liquid separation, performance of various solid-liquid separation technologies, separation enhancement methods, and design considerations. An overview of various farm scale separation technologies is also presented in the solid-liquid separation document.
http://www.extension.org/67702 Land application of manure in regions with intense confined livestock and poultry production is an environmental concern when land is limiting because it promotes soil phosphorus (P) surplus and potential pollution of water resources. A net accumulation of soil P results from the disproportion between lower nitrogen (N) and P ratio (N:P) in animal manure and the higher N:P ratio in harvested crops. Although manure can be moved off the farm, its transportation becomes less economical with increasing distances from the source. Thus, management alternatives to land application are needed to resolve agronomic P imbalances for more effective recycling of manure P.
This presentation is from the 22nd Tcl Conference (Manassas, VA, 21-23 October 2015). It's where I describe where we've got up to with compiling Tcl to native machine code.
EdSketch: Execution-Driven Sketching for JavaLisa Hua
Sketching is a relatively recent approach to program synthesis, which has shown much promise. The key idea in sketching is to allow users to write partial programs that have “holes” and provide test harnesses or reference implementations, and let synthesis tools create program fragments that the holes such that the resulting complete program has the desired functionality. Traditional solutions to the sketching problem perform a translation to SAT and employ CEGIS. While e ective for a range of programs, when applied to real applications, such translation-based approaches have a key limitation: they require either translating all relevant libraries that are invoked directly or indirectly by the given sketch – which can lead to impractical SAT problems – or creating models of those libraries – which can require much manual effort.
is paper introduces execution-driven sketching, a novel approach for synthesis of Java programs using a backtracking search that is commonly employed in so ware model checkers. e key novelty of our work is to introduce effective pruning strategies to effciently explore the actual program behaviors in presence of libraries and to provide a practical solution to sketching small parts of real-world applications, which may use complex constructs of modern languages, such as reflection or native calls. Our tool EdSketch embodies our approach in two forms: a stateful search based on the Java PathFinder model checker; and a stateless search based on re-execution inspired by the VeriSoft model checker. Experimental results show that EdSketch’s performance compares well with the well-known SAT-based Sketch system for a range of small but complex programs, and moreover, that EdSketch can complete some sketches that require handling complex constructs.
This week, Luke Pearson (Polychain Capital) and Joshua Fitzgerald (Anoma) present their work on Plonkup, a protocol that combines Plookup and PLONK into a single, efficient protocol. The protocol relies on a new hash function, called Reinforced Concrete, written by Dmitry Khovratovich. The three of them will present their work together at this week's edition of zkStudyClub!
Slides:
---
To Follow the Zero Knowledge Podcast us at https://www.zeroknowledge.fm
To the listeners of Zero Knowledge Podcast, if you like what we do:
- Follow us on Twitter - @zeroknowledgefm
- Join us on Telegram - https://t.me/joinchat/TORo7aknkYNLHmCM
- Support our Gitcoin Grant - https://gitcoin.co/grants/329/zero-knowledge-podcast-2
- Support us on Patreon - https://www.patreon.com/zeroknowledge
Introduction to Neural Networks and Deep Learning from ScratchAhmed BESBES
If you're willing to understand how neural networks work behind the scene and debug the back-propagation algorithm step by step by yourself, this presentation should be a good starting point.
We'll cover elements on:
- the popularity of neural networks and their applications
- the artificial neuron and the analogy with the biological one
- the perceptron
- the architecture of multi-layer perceptrons
- loss functions
- activation functions
- the gradient descent algorithm
At the end, there will be an implementation FROM SCRATCH of a fully functioning neural net.
code: https://github.com/ahmedbesbes/Neural-Network-from-scratch
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
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
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
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
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
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
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
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
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
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
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
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