Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pairing Heaps - Advanced Data Structures - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advanced Data Structures which includes Split Algorithm, Unbalanced Binary Search Trees, Forward Pass, Forward Pass Example, Backward Cleanup Pass, Retrace Path, Current Nodes, Roots of Respective Tries, Branch Nodes etc. Key important points are: Pairing Heaps, Fibonacci Heaps, Runtime Overheads, Space Per Node, Specified Manner, Node Structure, Left and Right Sibling, Max Pairing Heap, Compare-Link Operation, Worst-Case Degree

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharmakeerti
dharmakeerti 🇮🇳

4.2

(26)

91 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Pairing Heaps
Fibonacci
Pairing
Insert O(1) O(1)
Remove min (or max)
O(n) O(n)
Meld O(1) O(1)
Remove O(n) O(n)
Decrease key (or
increase) O(n) O(1)
Pairing Heaps
Fibonacci
Pairing
Insert O(1) O(log n)
Remove min (or max)
O(log n) O(log n)
Meld O(1) O(log n)
Remove O(log n) O(log n)
Decrease key (or
increase) O(1) O(log n)
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Pairing Heaps - Advanced Data Structures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Pairing Heaps

Fibonacci Pairing

Insert O(1) O(1)

Remove min (or max) O(n) O(n)

Meld O(1) O(1)

Remove O(n) O(n)

Decrease key (or

increase)

O(n) O(1)

Pairing Heaps

Fibonacci Pairing

Insert O(1) O(log n)

Remove min (or max) O(log n) O(log n)

Meld O(1) O(log n)

Remove O(log n) O(log n)

Decrease key (or

increase)

O(1) O(log n)

Pairing Heaps

• Experimental results suggest that pairing

heaps are actually faster than Fibonacci

heaps.

ƒ Simpler to implement.

ƒ Smaller runtime overheads.

ƒ Less space per node.

Definition

• A min (max) pairing heap is a min (max) tree in

which operations are done in a specified manner.

Insert

• Create 1 -element max tree with new item

and meld with existing max pairing heap.

insert(2)

Insert

• Create 1 -element max tree with new item

and meld with existing max pairing heap.

insert(14)

• Actual cost = O(1).

Worst-Case Degree

• Insert 9 , 8 , 7 , …, 1 , in this order.

• Worst-case degree = n –1.

Worst-Case Height

• Insert 1 , 2 , 3 , …, n, in this order.

• Worst-case height = n.

IncreaseKey(theNode, theAmount)

Meld subtree with remaining tree.

IncreaseKey(theNode, theAmount)

• Actual cost = O(1).

Remove Max

• If empty => fail.

• Otherwise, remove tree root and meld

subtrees into a single max tree.

• How to meld subtrees?

ƒ Good way => O(log n) amortized complexity

for remove max.

ƒ Bad way => O(n) amortized complexity.

Bad Way To Meld Subtrees

• currentTree = first subtree.

• for (each of the remaining trees)

currentTree = compareLink(currentTree,

nextTree);

Good Ways To Meld Subtrees

• Two-pass scheme.

• Multipass scheme.

• Both have same asymptotic complexity.

• Two-pass scheme gives better observed

performance.

Two-Pass Scheme

• Pass 1.

ƒ Examine subtrees from left to right.

ƒ Meld pairs of subtrees, reducing the number of

subtrees to half the original number.

ƒ If # subtrees was odd, meld remaining original

subtree with last newly generated subtree.

• Pass 2.

ƒ Start with rightmost subtree of Pass 1. Call this

the working tree.

ƒ Meld remaining subtrees, one at a time, from

right to left, into the working tree.

Two-Pass Scheme – Example

T1 T2 T3 T4 T5 T6 T7 T

S1 S2 S3 S

Two-Pass Scheme – Example

S1 S2 S3 S

R

R

R

Multipass Scheme--Example

S1 S2 S

T7 T

S1 S2 S3 S

S3 S

R

R

R

Multipass Scheme--Example

R1 R

Q

• Actual cost = O(n).

Remove Nonroot Element

• Remove theNode from its sibling list.

• Meld children of theNode using either 2 -pass

or multipass scheme.

• Meld resulting tree with what’s left of

original tree.

Remove(theNode)

Remove theNode from its doubly-linked sibling list.

theNode

Remove(theNode)

• Actual cost = O(n).