Pairing Heaps. Experimental results suggest that pairing heaps are actually faster than Fibonacci heaps.  Simpler to implement.  Smaller runtime overheads.

Slides:



Advertisements
Similar presentations
Fibonacci Heaps Especially desirable when the number of calls to Extract-Min & Delete is small (note that all other operations run in O(1) This arises.
Advertisements

Splay Trees Binary search trees.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Chapter 4: Trees Part II - AVL Tree
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
1 Finger search trees. 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2) : Assumes that.
Analysis Of Fibonacci Heaps. MaxDegree Let N i = min # of nodes in any min (sub)tree whose root has i children. N 0 = 1. N 1 =
1 Pertemuan 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
1 B trees Nodes have more than 2 children Each internal node has between k and 2k children and between k-1 and 2k-1 keys A leaf has between k-1 and 2k-1.
Min-Max Heaps A double-ended priority queue is a data structure that supports the following operations: inserting an element with an arbitrary key deleting.
1 Pertemuan 20 Binomial Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Rank-Pairing Heaps Bernhard Haeupler, Siddhartha Sen, and Robert Tarjan, ESA
Binomial Heaps. Min Binomial Heap Collection of min trees
Dijkstra/Prim 1 make-heap |V| insert |V| delete-min |E| decrease-key Priority Queues make-heap Operation insert find-min delete-min union decrease-key.
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Chapter 10 Search Structures Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures.
CS Data Structures Chapter 5 Trees. Additional Binary Tree Operations (1/7)  Copying Binary Trees  we can modify the postorder traversal algorithm.
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
CSC 172 DATA STRUCTURES. Priority Queues Model Set with priorities associatedwith elements Priorities are comparable by a < operator Operations Insert.
Leftist Trees Linked binary tree. Can do everything a heap can do and in the same asymptotic complexity.  insert  remove min (or max)  initialize Can.
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
Chapter 9 Heap Structures
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Chap 9 Priority Queues. Operations supported by priority queue The functions that have been supported: –SP1: Return an element with minmum priority –SP2:
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
Advanced Data Structures and Implementation Top-Down Splay Trees Top-Down Splay Trees Red-Black Trees Red-Black Trees Top-Down Red Black Trees Top-Down.
Priority Queue. Priority Queues Queue (FIFO). Priority queue. Deletion from a priority queue is determined by the element priority. Two kinds of priority.
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
Oct 26, 2001CSE 373, Autumn A Forest of Trees Binary search trees: simple. –good on average: O(log n) –bad in the worst case: O(n) AVL trees: more.
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue. Nov 4,
Double-Ended Priority Queues Primary operations  Insert  Remove Max  Remove Min Note that a single-ended priority queue supports just one of the above.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
CS 367 Introduction to Data Structures Lecture 8.
Dynamic Dictionaries Primary Operations:  get(key) => search  put(key, element) => insert  remove(key) => delete Additional operations:  ascend()
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Fibonacci Heaps. Analysis FibonacciAnalysis.ppt Video  iew/cop5536sahni
1 Fibonacci heaps: idea List of multiway trees which are all heap-ordered. Definition: A tree is called heap-ordered if the key of each node is greater.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
Fibonacci Heaps. Fibonacci Binary insert O(1) O(log(n)) find O(1) N/A union O(1) N/A minimum O(1) O(1) decrease key O(1) O(log(n)) delete O(log(n) O(log(n))
Leftist Trees Linked binary tree.
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Splay Trees Binary search trees.
Finger search trees.
Chapter 11: Multiway Search Trees
Binomial Heaps On the surface it looks like Binomial Heaps are great if you have no remove mins. But, in this case you need only keep track of the current.
Lecture 22 Binary Search Trees Chapter 10 of textbook
Double-Ended Priority Queues
Bohyung Han CSE, POSTECH
Splay Trees Binary search trees.
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
Interval Heaps Complete binary tree.
Pairing Heaps Actual Complexity.
Initializing A Max Heap
A simpler implementation and analysis of Chazelle’s
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
Fibonacci Heaps.
Heaps By JJ Shepherd.
Pairing Heaps Actual Complexity
A Heap Is Efficiently Represented As An Array
Splay Trees Binary search trees.
Presentation transcript:

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

Node Structure Child  Pointer to first node of children list. Left and Right Sibling  Used for doubly linked linked list (not circular) of siblings.  Left pointer of first node is to parent.  x is first node in list iff x.left.child = x. Data Note: No Parent, Degree, or ChildCut fields.

Meld – Max Pairing Heap Compare-Link Operation  Compare roots.  Tree with smaller root becomes leftmost subtree = Actual cost = O(1).

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. 12 Worst-case height = n. 345

IncreaseKey(theNode, theAmount) Since nodes do not have parent fields, we cannot easily check whether the key in theNode becomes larger than that in its parent. So, detach theNode from sibling doubly- linked list and meld.

IncreaseKey(theNode, theAmount) If theNode is not the root, remove subtree rooted at theNode from its sibling list theNode

IncreaseKey(theNode, theAmount) Meld subtree with remaining tree

IncreaseKey(theNode, theAmount) Actual cost = O(1).

Delete 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);

Example Delete max Meld into one tree

Example Actual cost of insert is 1. Actual cost of delete max is degree of root. n/2 inserts (9, 7, 5, 3, 1, 2, 4, 6, 8) followed by n/2 delete maxs.  Cost of inserts is n/2.  Cost of delete maxs is … + n/2 – 1 =  (n 2 ).  If amortized cost of an insert is O(1), amortized cost of a delete max must be  (n).

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 T2T3T4T1T6T7T8T5 S1S2S3S4

Two-Pass Scheme – Example S1S2S3S4 R1 R2 R3

Multipass Scheme Place the subtrees into a FIFO queue. Repeat until 1 tree remains.  Remove 2 subtrees from the queue.  Meld them.  Put the resulting tree onto the queue.

Multipass Scheme – Example T2T1T3T4T6T7T8T5 S2S1 T6T7T8T5 S1 T3T4T6T7T8T5 S3S2S1 T7T8

Multipass Scheme--Example S3S2S1 T7T8 S4S3S2S1 S4S3 R1 R2

Multipass Scheme--Example R1R2 Q1 Actual cost = O(n).

Delete 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.

Delete(theNode) Remove theNode from its doubly-linked sibling list theNode

Delete(theNode) Meld children of theNode

Delete(theNode) Meld with what’s left of original tree

Delete(theNode) Actual cost = O(n).