1 Fat heaps (K & Tarjan 96). 2 Goal Want to achieve the performance of Fibonnaci heaps but on the worst case. Why ? Theoretical curiosity and some applications.

Slides:



Advertisements
Similar presentations
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)
Advertisements

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.
Advanced Data structure
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.
Theory of Computing Lecture 8 MAS 714 Hartmut Klauck.
Advanced Data Structures
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Advanced Data Structures Chapter 16. Priority Queues Collection of elements each of which has a priority. Does not maintain a first-in, first-out discipline.
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
CS 253: Algorithms Chapter 6 Heapsort Appendix B.5 Credit: Dr. George Bebis.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
A Binary Tree root leaf. A Binary Tree root leaf descendent of root parent of leaf.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Nick Harvey & Kevin Zatloukal
Trees and Red-Black Trees Gordon College Prof. Brinton.
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.
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.
1 Binary heaps binary tree that satisfy two properties –structural property (is a complete tree) –heap-ordering property (minimum item on top) Can have.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
The Euler-tour technique
1 Red Black Trees (Guibas Sedgewick 78). 2 Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2)
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
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.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 11 Tuesday, 12/4/01 Advanced Data Structures Chapters.
Binary Trees Chapter 6.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 Priority Queues (Heaps)  Sections 6.1 to The Priority Queue ADT  DeleteMin –log N time  Insert –log N time  Other operations –FindMin  Constant.
1 Binomial heaps, Fibonacci heaps, and applications.
Algorithms 2005 Ramesh Hariharan. Amortization in Dynamic Algorithms A single insertion/deletion might take say O(log n) time Does a sequence of n insertions.
CHAPTER 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
Strict Fibonacci Heaps Gerth Stølting Brodal Aarhus University George Lagogiannis Robert Endre Tarjan Agricultural University of Athens Princeton University.
Binomial heaps, Fibonacci heaps, and applications
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Data Structures Week 8 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
Sorting. Pseudocode of Insertion Sort Insertion Sort To sort array A[0..n-1], sort A[0..n-2] recursively and then insert A[n-1] in its proper place among.
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:
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Four different data structures, each one best in a different setting. Simple Heap Balanced Heap Fibonacci Heap Incremental Heap Our results.
Heaps & Priority Queues
Tree Data Structures. Heaps for searching Search in a heap? Search in a heap? Would have to look at root Would have to look at root If search item smaller.
1 Heaps A heap is a binary tree. A heap is best implemented in sequential representation (using an array). Two important uses of heaps are: –(i) efficient.
CMSC 341 Binomial Queues and Fibonacci Heaps. Basic Heap Operations OpBinary Heap Leftist Heap Binomial Queue Fibonacci Heap insertO(lgN) deleteMinO(lgN)
Kinetic Heaps K, Tarjan, and Tsioutsiouliklis. Broadcast Scheduling Parametric and Kinetic Heaps Broadcast Scheduling Using a Kinetic Heap The Computational.
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.
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
Binomial heaps, Fibonacci heaps, and applications
Finger search trees.
Heaps Binomial Heaps Lazy Binomial Heaps 1.
Binomial heaps, Fibonacci heaps, and applications
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Binary Trees, Binary Search Trees
© 2013 Goodrich, Tamassia, Goldwasser
Fundamental Structures of Computer Science
Strict Fibonacci Heaps
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Binomial heaps, Fibonacci heaps, and applications
Binomial heaps, Fibonacci heaps, and applications
Red Black Trees (Guibas Sedgewick 78)
Binomial heaps, Fibonacci heaps, and applications
Heaps 9/29/2019 5:43 PM Heaps Heaps.
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

1 Fat heaps (K & Tarjan 96)

2 Goal Want to achieve the performance of Fibonnaci heaps but on the worst case. Why ? Theoretical curiosity and some applications

3 Applications Implement Dijkstra’s algorithm in parallel on an EREW PRAM. Where can we exploit parallelizm ? When we scan a vertex v and there are many edges outgoing of v.

4 The algorithm The  (v) edges incident with every vertex v are divided evenly among the processors such that each processor is responsible for either p  (v) p + 1oredges

5 The algorithm (cont.) Each processor maintains a heap. At the start of each iteration, the heap of p i contain every vertex of V-S with key d i (v) = min{d(u) + w(u,v) | u  S and (u,v) assigned to p i } S V-S

6 The algorithm (cont.) Iteration of Dijkstra: 1) Each processor finds the minimum in its heap. (find-min). 2) Find the minimum among the results of the find-mins, and the vertex v which achieves it. 3) Broadcast v and d(v) to all processors. 4) Each processor does a delete(v) 5) Each processor scans the edges out of v assigned to it and make the appropriate decrease-key on its heap if needed. (using d(v))

7 PRAM basics 1) Can “Broadcast” a value v to p processors in O(log p) time 2) p processors, each holding a value can calculate the minimum in O(log p) time

8 The algorithm (cont.) Iteration of Dijkstra: 1) Each processor finds the minimum in its heap. (find-min). 2) Find the minimum among the results of the find-mins, and the vertex v which achieves it. 3) Broadcast v and d(v) to all processors. 4) Each processor does a delete(v) 5) Each processor scans the edges out of v assigned to it and make the appropriate decrease-key on its heap if needed. (using d(v)) O(1) O(log p) O(log n) O(  (v) p + 1 )

9 Summing up over all iterations we obtain that the time is O(m/p + nlog(n)) Space O(m + n*p) If m  nlogn take p = m/n(log n) and Dijkstra would run in O(nlog n) time and O(m) space For p  m/n(log n) Dijkstra would run in O(m/p) time and O(m) space. What is the problem with all this ? Everything should be syncronized and time bounds are amortized

10 Redundant binary counters (Clancy & Knuth 77) Lets get started from insert, How do we make insert O(1) on the worst case and keeping logarithmic worst case bounds for the other operations. Insert is more or less like adding one to a binary number So maybe we want first to be able to get a binary counter supporting increment in O(1) time on the worst case. Go back to binomial heaps.

11 Redundant binary counters (cont) We shall allow an additional digit. Use 0,1, and 2, but keep the base to be 2 ! = 0* * * * *2 4 = 38 The representation now is not unique Can represent 38 also by or We shall exploit the redundancy.

12 Exploiting the redundancy We are not going to use all possible representations Define a representation to be regular if it does not contain the following patterns …… …... ………… When you walk from left to right after you see a 2 you should see a 0 before hitting another 2 or running out of digits

13 Exploiting the redundancy (cont) Note: every number has a regular representation. Given a regular representation for x, how do you get a regular representation for x+1. 1) increment the rightmost digit. We get a representation for x+1 which may not be regular ……… ==> ……… ) If indeed so, then replace the rightmost 2 with a 0 and increment the digit to its left. (Fix) ==> ………

14 Exploiting the redundancy (cont) Lemma: we end up with a regular representation for x+1. Proof: Clear if we have not created a 2. Suppose that we create a 2: ……… ==> ……… There is a zero between the new 2 and a 2 to its left because there was a zero between the old 2 and the 2 to its left.

15 Exploiting the redundancy (cont) We change only O(1) digits but can we implement it in O(1) time ? Yes! Represent the number as a sorted list with forward pointers: Have to update forward pointer when you create a one. If a 1 is followed by a sequence of 1’s and a 2 then its forward pointer point to that 2.

16 Can incrementing an arbitrary digit To increment d i : Fix d i if d i = 2 increment d i if d i+1 = 1 and the first d j, j>i+1 such d j  1 is 2 then fix d j Fix d i if d i = 2

17 Back to heaps Allow 0,1,2 binomial heaps of each rank. Trees are hanging off a redundant counter. The i-th digit of the counter corresponds to the number of rank i trees The representation in the counter must be regular.

18 Back to heaps (cont) Insert now is like adding one to the redundant binary counter While incrementing if we need to fix a 2 then it corresponds to linking two binomial trees of rank i to a binomial tree of rank i

19 Back to heaps (cont) Do other operations essentially as before. Next, lets try to add a decrease key, in O(1) worst case time, without hurting other operations

20 Some additional facts about redundant counters The idea extends from base 2 to any base. For example in base 3 the forbidden configurations would be …………… …. ………………… We can increment any digit in O(1) time if we get access to it.

21 Fat binomial trees FB 0 FB 1 FB (i-1) FB i FB (i-1)

22 Fat binomial trees FB 0 FB 1 FB (i-2) FB (i-1)... FB i

23 Properties of fat binomial trees 1) | FB k | = 3 k 2) degree(root(FB k )) = 2k 3) depth(FB k ) = k ==> The degree and depth of a binomial tree with at most n nodes is O( log(n)). Define the rank of FB k to be k

24 Fat heaps (def) A collection of fat binomial trees at most 3 of every rank. Items in the nodes. Trees are hanging off of a redundant base 3 counter which is regular. So far, the bounds for all operations are as before. For efficient decrease key, allow violations to the heap order. A violation is a node that is smaller than it parent. Allow at most two such nodes of every rank in all trees

25 Fat heaps (example)

26 Organizing violations Use another redundant binary counter. The i-th digit corresponds to violations of rank i and stores pointers to these violating nodes. Counter must be regular ……………… Access the counters via arrays

27 Operations Insert(x,h): essentially as before. Deletemin(h): add the subtrees by performing increments to the root counter. The new minimum is either at a root or at a violating node. We search for it and if it is in a violating node we swap it with one of the roots. Delete(x,h): decrease-key(x,h,  ), deletemin(h) O(1) O(log n)

28 Decrease key(x,h,  ) Decrease the key of x by . If x becomes the minimum swap it with the minimum item. We may have created new rank i violation. So we need to increment digit i of the violation counter. This may require a fix operation on some digits. A fix operation corresponds to converting two violations of rank i to one violation of rank i+1. How do we do that ?

29 Decrease key(x,h,  ) (cont) First arrange the two violations to have the same root. (the one with larger key) ==>

30 Decrease key(x,h,  ) (cont) Case 1: The parent of the two rank i violations is of rank i Cut the two violating nodes and their parent. That gives 3 rank i trees. Link them to one rank i+1 tree which replaces the parent of the two violations

31 Decrease key(x,h,  ) (cont) Case 2: The parent of the two rank i violations is of rank at least i This parent must have a non-violating child w of rank i+1. This child must have two non violating rank i children w

32 Decrease key(x,h,  ) (cont) Replace the violating subtrees with the rank i subtrees of w. Cut w (without its leftmost subtrees). Link the subtree rooted by w with the violating subtrees. Use the resulting subtree to replace w w 238 ==>

33 Meld(h1,h2) ……………… ……………… Fix all violations in h1 and then insert the subtrees of h1 into the counter of h2 by doing increments