Solutions of Theory of Algorithms assignment 19.2-4

# Solutions of Theory of Algorithms assignment 19.2-4 - Thus...

This preview shows pages 1–2. Sign up to view the full content.

Solutions of Theory of Algorithms assignment Exercise 19.2-4 From the definition of binomial heap, it can't contain two binomial trees of the same degree. So, when we union two binomial heaps together, we merge the trees of the same degree together if any. So there could be three cases during the union operation: First: there is only one binomial tree of degree k in both heaps. Second: there are two trees of the same degree; each one is original in its old heap. Third: there exist three trees of the same degree; the third one result from previous merge. Keeping the degree of each binomial tree in the heap unique, and the smaller ones precede the higher ones, maintains the properties of the binomial heap.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Thus the BINOMIAL HEAP UNION is correct. Problem 19.1 a.MINIMUM min= infinity min_key=nil For every leaf in the tree If key[x]<min min= key[x] min_key=x return min_key b.decrease_key(x,k) key[x]=k if key[x]< small[x] small[x]=key[x] c.insert (x,k) flag=yes for every internal node if it has 2 or 3 leaves new _leaf (x) key[x]=k exit loop else flag= no if flag = no (no empty place for inserting the leaf) merge (H, k) d.delete x decrease_key(x,-infinity) if parent (x) has 2 leaves delete leaf x merge(sub tree parent(x),H) else delete leaf x e.extract_min(h) x=minimum(H) delete(x)...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Solutions of Theory of Algorithms assignment 19.2-4 - Thus...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online