Pairing Heaps Actual Complexity.

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
Advanced Data structure
Analysis Of Binomial Heaps. Operations Insert  Add a new min tree to top-level circular list. Meld  Combine two circular lists. Remove min  Pairwise.
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.
Pairing Heaps. Experimental results suggest that pairing heaps are actually faster than Fibonacci heaps.  Simpler to implement.  Smaller runtime overheads.
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.
Analysis Of Binomial Heaps. Operations Insert  Add a new min tree to top-level circular list. Meld  Combine two circular lists. Delete min  Pairwise.
1 Pertemuan 20 Binomial Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Binomial Heaps. Min Binomial Heap Collection of min trees
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
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
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.
Chapter 9 Heap Structures
Chapter 21 Priority Queue: Binary Heap Saurav Karmakar.
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.
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.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
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,
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.
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.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
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.
Multiway Search Trees Data may not fit into main memory
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
BST Trees
Splay Trees Binary search trees.
Data Structures & Algorithms
Finger search trees.
Analysis Of Binomial Heaps
Chapter 11: Multiway Search Trees
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
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
Hashing Exercises.
Double-Ended Priority Queues
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Bohyung Han CSE, POSTECH
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Dynamic Dictionaries Primary Operations: Additional operations:
Insert in amortized cost O(1), Merge in O(lgn) DeleteMax in O(lgn)
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.
7/23/2009 Many thanks to David Sun for some of the included slides!
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Initializing A Max Heap
Height Balanced Trees 2-3 Trees.
A simpler implementation and analysis of Chazelle’s
© 2013 Goodrich, Tamassia, Goldwasser
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
Binary and Binomial Heaps
Binomial heaps, Fibonacci heaps, and applications
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.
Pairing Heaps Actual Complexity
A Heap Is Efficiently Represented As An Array
Splay Trees Binary search trees.
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Heaps.
Presentation transcript:

Pairing Heaps Actual Complexity

Pairing Heaps Amortized Complexity Pairing heap amortized analysis (two pass scheme): Improved upper bounds for pairing heaps, John Iacono, arxiv:1110.4428v3, 2014. Amortized complexity of increase/decrease key is Omega(log log n). Amortized Complexity

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. 3 5 8 1 2 4 6 Max Tree

Node Structure Child Left and Right Sibling Data 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 Actual cost = O(1). Compare roots. Tree with smaller root becomes leftmost subtree. 3 6 7 9 6 7 3 6 7 9 + = Compare-link is similar to the pairwise combining operation used in binomial and Fibonacci heaps. The difference is that in the compare-link operation the two trees may not have the same degree. Leftmost or next to leftmost is easiest place to add new tree. Actual cost = O(1).

Insert Create 1-element max tree with new item and meld with existing max pairing heap. 3 6 7 9 2 3 6 7 9 = + insert(2)

Insert Create 1-element max tree with new item and meld with existing max pairing heap. 3 6 7 9 14 3 6 7 9 = + 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. 5 4 3 Worst-case height = n. 2 1

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) 1 2 6 9 4 5 3 theNode IncreaseKey(theNode,14). If theNode is not the root, remove subtree rooted at theNode from its sibling list.

IncreaseKey(theNode, theAmount) 18 9 6 2 2 3 4 5 1 6 3 2 3 1 Meld subtree with remaining tree.

IncreaseKey(theNode, theAmount) 18 2 1 2 6 9 4 5 3 3 3 Doubly linked list is required to detach theNode from its sibling list in O(1) time. Can’t use copy from next node trick used in Binomial heaps, because of the pointers from the external world to nodes in the data structure. These pointers enable the remove(theNode) and decreaseKey(theNode, theAmount) operations. Detach first node  change parent i.e., left sibling) & child pointers. 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);

Example Remove max. Meld into one tree. 9 7 5 2 6 8 4 1 3 7 5 2 6 8 4 After 2 removemaxs we look like the original tree. 8 6 1 5 7 3 2 4 Meld into one tree.

Example Actual cost of insert is 1. Actual cost of remove max is degree of root. n/2 inserts (9, 7, 5, 3, 1, 2, 4, 6, 8) followed by n/2 remove maxs. Cost of inserts is n/2. Cost of remove maxs is 1 + 2 + … + n/2 – 1 = Q(n2). If amortized cost of an insert is O(1), amortized cost of a remove max must be Q(n). Actually, if amortized cost of insert is less than Omega(n), that of remove max must be Omega(n). Otherwise we cannot get a sequence cost that is Theta(n2).

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. Pass 2. 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 If there is a T9, meld with S4 before proceeding to Pass 2.

Two-Pass Scheme – Example R3 R2 R1

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

Multipass Scheme--Example R1 R1 R2

Multipass Scheme--Example R1 R2 Q1 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) theNode 1 2 6 9 4 5 3 theNode When the leftmost child is removed, we change the child pointer in the parent node. Note that the left sibling pointer in the leftmost child gets us to the parent. Remove theNode from its doubly-linked sibling list.

Remove(theNode) Meld children of theNode. 9 6 2 6 4 1 1 4 5 2 3 3 2 4

Remove(theNode) Meld with what’s left of original tree. 9 6 2 6 1 4 1 5 3 3 2 4 2 3 1 Meld with what’s left of original tree.

Remove(theNode) 9 6 3 2 6 2 3 1 4 1 5 3 2 4 Actual cost = O(n). 1