1 / 28

ANALYSIS OF SOFT HEAP

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

Download Presentation

ANALYSIS OF SOFT HEAP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ANALYSIS OF SOFT HEAP Varun Mishra April 16,2009

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

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

  4. Data Structure 0 1 2 3,2,4 1 11 4 13,8,15,24 6 4 24 11 • 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 4 8 6 7

  5. 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”. 2,3,4 4

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

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

  8. 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] < key[suffix_min[h->next)]) suffix_min[h] = h Else suffix_min[h] = suffix_min[h->next] UpdateSuffix_min(h->prev) }

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

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

  11. 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; } }

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

  13. Sift 2 3 empty 7 4 9 4 11 7 8 15 9 4 Let delete min was called in the current setting.

  14. Sift 2 3 empty 7 4 9 4 11 7 8 15 9 Φ The value at leaf node set to Φ.

  15. Sift 2 3 empty 7 4 9 4 11 7 Φ 15 9 8 Φ and 8 swapped.

  16. Sift 2 3 empty 7 4 8 9 8 11 7 8 Φ 15 9 8 8 copied upwards in item list of parent.

  17. Sift 2 3 8 7 8 8 9 8 11 7 8 Φ 15 9 8 8 copied upwards in item list of parent. Now 8 can be deleted.

  18. Sift - II 2 3 8 v 7 8 8 9 8 11 7 8 Φ 15 9 8 Consider other scenario where the node V had rank > r. Sift called again.

  19. Sift - II 2 3 8 v 7 8 8 9 8 11 7 Φ 15 9 Φ

  20. Sift - II 2 3 8 v 7 8 9 Φ 11 7 15 9 Nodes with Φ key are pruned.

  21. Sift - II 2 3 8 v 7 8 11 9 7 Φ 15 9 Swap Φ and 9.

  22. Sift - II 2 3 8,9 v 7 9 11 9 7 Φ 15 9 Append 9 into the item list of V. Note that 8 is now a corrupted key.

  23. 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/2r . Together with definition of r and bound on item-list, we can prove it.)

  24. 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 H1 + 2k * log(n/ 2k ) where H = log(n) = O(n) • We can charge the dismantle-induced melds against the absent leaves.

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

  26. 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)2n + .... = O(n).

  27. Applications • Approximate Sorting Insert the n items in a soft heap and delete the minimum items repeatedly. Total number of inversions is bounded by εn2. So we can do a near/approximate sorting in O(n) with atmost εn2 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

  28. Thank You

More Related