ANALYSIS OF SOFT HEAP Varun Mishra April 16,2009.

Slides:



Advertisements
Similar presentations
§6 Leftist Heaps CHAPTER 5 Graph Algorithms  Heap: Structure Property + Order Property Target : Speed up merging in O(N). Leftist Heap: Order Property.
Advertisements

COL 106 Shweta Agrawal and Amit Kumar
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
Trees Types and Operations
Advanced Data structure
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Priority Queues And the amazing binary heap Chapter 20 in DS&PS Chapter 6 in DS&AA.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
CSE 373 Data Structures Lecture 12
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.
Priority Queues1 Part-D1 Priority Queues. Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is.
5.9 Heaps of optimal complexity
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
1 BST Trees A binary search tree is a binary tree in which every node satisfies the following: the key of every node in the left subtree is.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 Binomial heaps, Fibonacci heaps, and applications.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
The Power of Incorrectness A Brief Introduction to Soft Heaps.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
Chapter 21 Binary Heap.
David Stotts Computer Science Department UNC Chapel Hill.
Chapter 21 Priority Queue: Binary Heap Saurav Karmakar.
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
1 Heaps (Priority Queues) You are given a set of items A[1..N] We want to find only the smallest or largest (highest priority) item quickly. Examples:
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
8 January Heap Sort CSE 2011 Winter Heap Sort Consider a priority queue with n items implemented by means of a heap  the space used is.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
CMSC 341 Binomial Queues and Fibonacci Heaps. Basic Heap Operations OpBinary Heap Leftist Heap Binomial Queue Fibonacci Heap insertO(lgN) deleteMinO(lgN)
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
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.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
Heaps and Priority Queues What is a heap? A heap is a binary tree storing keys at its internal nodes and satisfying the following properties:
Heaps and Heap Sort. Sorting III / Slide 2 Background: Complete Binary Trees * A complete binary tree is the tree n Where a node can have 0 (for the leaves)
Leftist Trees Linked binary tree.
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Binomial heaps, Fibonacci heaps, and applications
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Binomial Priority Queues
Priority Queues and Heaps
Part-D1 Priority Queues
A simpler implementation and analysis of Chazelle’s
Tree Representation Heap.
ערמות בינומיות ופיבונצ'י
Heap Sort CSE 2011 Winter January 2019.
CS 583 Analysis of Algorithms
Binary Heaps What if we’re mostly concerned with finding the most relevant data? A binary heap is a binary tree (2 or fewer subtrees for each node) A heap.
Data Structures and Analysis (COMP 410)
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Binomial heaps, Fibonacci heaps, and applications
Algorithms: Design and Analysis
Priority Queues CSE 373 Data Structures.
Binomial Priority Queues
CSE 373, Copyright S. Tanimoto, 2002 Priority Queues -
Binomial heaps, Fibonacci heaps, and applications
CS 6310 Advanced Data Structure Wei-Shian Wang
Fundamental Structures of Computer Science II
Heaps & Multi-way Search Trees
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

ANALYSIS OF SOFT HEAP Varun Mishra April 16,2009

Outline What is a Soft Heap? Data Structure Heap Operations insert, merge, deletemin,sift Complexity Bounds Applications

What is a Soft Heap? A sequence of heap ordered “binarized“ binomial trees(soft queues) with possibly some subtrees missing Acheives an amortized constant-time for meld,delete and findmin and O(log 1 / ε ) time for insert in a Heap. Atmost εn items may be corrupted where n is the number of inserts Uses the concept of “car pooling” to beat the logarithmic time bound Used for median finding, computing MST of a graph and approximate sorting

Data Structure Each item in head list has a suffix-min pointer An entire item-list can be stored at each node Heap ordering is on the common key 3,2,4 13,8,15,24

Additional points Binomial trees are arranged in the head-list in increasing order of rank. No two trees has same rank. Rank of a node is defined as the rank of the corresponding target node in a binomial tree The items in the item-list whose key is less than the node’s key are corrupted. All item-list members move together to implement “car pooling”. 4 2,3,4

Heap Operations : Insert Create a single node and meld it with the remaining soft heap

Meld Break the heap with lower rank and meld each soft queue into the other heap Insert the queue h into head list to maintain order in ranks Perform carry propagation if required Call update suffix_min

Update Suffix_min Let h was the head of the last queue that was modified. Update suffix_min pointers in a backward fashion UpdateSuffix_min(h) { If (key[h] next)]) suffix_min[h] = h Else suffix_min[h] = suffix_min[h->next] UpdateSuffix_min(h->prev) }

Delete and Findmin Delete : Simply mark the element to be deleted Findmin : Find the smallest un-marked item A variant DeleteMin will be implemented

DeleteMin Follow the suffix_min pointer from beginning of head- list and delete the item from item list of root If the item-list is empty, we need to refill it. Before doing so, we check if the following rank invariant holds : #(children) of root >= Rank(root)/2. If not, we dismantle the root to meld back its children into the heap.

Root dismantling if (childcount_h < rank(h)/2) { h->prev->next = h->next; h->next->prev = h->prev; UpdateSuffix_Min(h->prev); temp = h; while (tmp->next <> NULL) { meld (tmp->child); tmp = tmp->next; }

Sift : refilling the item list Append the item list of node v with itemlist of v->next. Copy key(v->next) into key(v). (Swap child and next pointers if necessary) If (rank(v) > r and rank(v)%2 == 1 ) Call sift again. (this extra call results in corruption) r is defined as r = 2 + 2[ log 1 / ε]. This ensures that corruption occurs only at lower depths of heap.

Sift empty Let delete min was called in the current setting.

Sift Φ empty The value at leaf node set to Φ.

Sift Φ 8 empty Φ and 8 swapped.

Sift Φ 8 empty 8 copied upwards in item list of parent. 8 8

Sift Φ copied upwards in item list of parent. Now 8 can be deleted. 8 8

Sift - II Φ 8 8 Consider other scenario where the node V had rank > r. Sift called again. 8 8 v

Sift - II Φ Φ 8 8 v

Sift - II Φ Nodes with Φ key are pruned. v

Sift - II Swap Φ and 9. v Φ

Sift - II ,9 v Φ Append 9 into the item list of V. Note that 8 is now a corrupted key.

Complexity Bounds |item –list(v)| <= max {1, 2^(rank[v/2]-r/2) } (can be shown by induction) #(Corrupted items) <= εn (Nodes with corrupted keys <= 1/2 r. Together with definition of r and bound on item-list, we can prove it.)

Meld We will show that total time taken for all melds is O(n) The entire sequence of soft heap melds can be modeled as a binary tree. So, MeldCost(x) = 1 + min { cost(Size[y]), cost(Size[z]) } Total cost <= ∑ k= 1 to H k * log(n/ 2 k ) where H = log(n) = O(n) We can charge the dismantle-induced melds against the absent leaves.

Sift Amortized cost for all refilling item-list operations is O(rn). Every call to sift takes O(r) time and results in increasing the size of item-list at a node by atleast 1. So there can be atmost 'n' calls to soft and the overall time complexity is O(rn). So it follows that all operations can be done in amortized constant time except insert – O(log 1 / ε ) which pays for the sift and eventual deletion of that element.

Applications Finding Median or kth largest element Insert the elements in a soft heap with error rate 1/3. Our aim is to find a nice pivot element. Call delete-min n/3 times. The largest element deleted has rank between n/3 and 2n/3. So after each iteration, we can remove atleast n/3 items from consideration. The overall running time is n + 2/3n + (2/3) 2 n = O(n).

Applications Approximate Sorting Insert the n items in a soft heap and delete the minimum items repeatedly. Total number of inversions is bounded by ε n 2. So we can do a near/approximate sorting in O(n) with atmost ε n 2 inversions. Minimum Spanning Tree in O(m * c(m,n)) where c is the classical inverse of Ackerman’s function. This is one of the fastest deterministic time algo for computing MST

Thank You