Lecture 6 — February 9, 2017 1 Wrapping up on Hashing

Total Page:16

File Type:pdf, Size:1020Kb

Lecture 6 — February 9, 2017 1 Wrapping up on Hashing CS 224: Advanced Algorithms Spring 2017 Lecture 6 | February 9, 2017 Prof. Jelani Nelson Scribe: Albert Chalom 1 Wrapping up on hashing Recall from las lecture that we showed that when using hashing with chaining of n items into m C log n bins where m = Θ(n) and hash function h :[ut] ! m that if h is from log log n wise family, then no C log n linked list has size > log log n . 1.1 Using two hash functions Azar, Broder, Karlin, and Upfal '99 [1] then used two hash functions h; g :[u] ! [m] that are fully random. Then ball i is inserted in the least loaded of the 2 bins h(i); g(i), and ties are broken randomly. log log n Theorem: Max load is ≤ log 2 + O(1) with high probability. When using d instead of 2 hash log log n functions we get max load ≤ log d + O(1) with high probability. n 1.2 Breaking n into d slots n V¨ocking '03 [2] then considered breaking our n buckets into d slots, and having d hash functions n h1; h2; :::; hd that hash into their corresponding slot of size d . Then insert(i), loads i in the least loaded of the h(i) bins, and breaks tie by putting i in the left most bin. log log n This improves the performance to Max Load ≤ where 1:618 = φ2 < φ3::: ≤ 2. dφd 1.3 Survey: Mitzenmacher, Richa, Sitaraman [3] Idea: Let Bi denote the number of bins with ≥ i balls. Let H(b) = height of ball b in its bin. Then in order for a bin to grow to height i+1, both bins that ball b hashed to had to be at least 2 Bi height i, so we get P(H(b) ≥ i + 1)) ≤ n . 2 Bi Bi+1 Bi 2 This gives us E(Bi+1) ≤ E(Number of balls with height ≥ i + 1) ≤ n , so n ≤ ( n ) . n As a base case, since there are only n balls we know that at most 2 bins can have a height of 2 B2 1 B3 1 B4 1 balls, giving us n ≤ 2 . Then using our recursive definition from above we get n ≤ 22 , n ≤ (22)2 , ..., and can get the rule B2+j ≤ 1 . n 22j 1 Once 22j >> n the probability is really small that a bin will have 2 + j balls, so j >> log log n ) no bins will have 2 + j balls with high probability. 2 n αi Formal: Let α6 = 2e , and αi+1 = e × n for i ≥ 6. Let Ei be the event that Bi ≤ αi. 1 We then need to show that P (8i ≥ 6;Ei) ≥ 1 − poly(n) . Claim 1: P ((Bi+1 > αi+1)j \j=1 Ej) ≤ P(E6) P(E7jE6) P(E8jE7;E6)::: T P Ei+1 \ ( Ej) \ j≤i P (Ei+1) P(Ei+1j Ej) = T ≤ T ( Ej) ( Ej) j≤i P P j≤i j=1 2 The denominator here is close to one, and the numerator is upper bounded by P(Bin(n; (αi=n) ) > αi+1). Consider the following experiment. We insert the balls one by one into the bins. Number the balls 1; :::; n and assign them to bins in increasing order of ball number. In our experiment we maintain two variables: X and Y. X is a Boolean ”flag" that starts as TRUE and becomes FALSE if any of E1; :::; Ei ever fail to hold. Y is a counter: it counts the number of balls of height at least i+1. We αi 2 want to say P((Y > αi+1) AND X)≤ P(Bin(n; ( n ) ) > αi+1). Let "A" be the event (Y > αi+1) alphai 2 AND "X" and "B" be the event "Bin(n; ( n ) ) > αi+1". So we want to show P(A) ≤ P(B). So, we're going along inserting balls 1,...,n. We're going to do what is called a "coupling argument" αi 2 (we will define some Bin(n; ( n ) ) random variable Z starting at 0 and gradually being incremented as we insert our balls, and Z and our X,Y will be defined on the same probability space so that A and B are dependent and easy to compare, but marginally A and B have the correct probabilities of occurring). When we assign ball j, there are two cases. Either X is already FALSE, in which 2 αi case we just set Y to 0 (we already know A failed) and we increment Z with probability p = n2 . Otherwise, if X is true, then we know there are exactly t ≤ αi bins of load ≥ i for some t. We label these bins 1,...,t in this time step (and the other bins are labeled t+1,...,n for some ordering 1 that doesn't matter). We then pick a uniform random variable U in [0,1]. If U is in [0; n2 ] then 1 2 we imagine the two bins j got hashed to are 1,1. If it's in [ n2 ; n2 ), then we imagine it got hashed 2 1 to bins 1 and 2. Etc. We slice up [0,1] into n buckets of size exactly n2 each such that the first t2 buckets all correspond to the t2 different ways we can hash to two heavy bins (i.e. bins with 1 2 2 load at least i). The remaining buckets of size n2 in [0,1] then correspond to all the other n − t different hash possibilities for ball j. We then adjust X as needed if some condition failed based on the U we drew (and potentially set Y to 0 if X got set to FALSE). We also increment Z iff U ≤ p. ***This is where the coupling happens***, since Z and X,Y are now defined on the same probability space based on these U random variables over our iterations! AND THE KEY THING: event "A" can only happen if "B" also happened, since the way we coupled Y and Z maintains the invariant that Y ≤ Z always (note we hold Y at 0 if X is ever set to FALSE)! Thus P(A) ≤ P(B). 2 αi Claim 2: P (Bin(n; n2 )) > αi+1. For those not aware Bin(n,p) refers to the distribution of the number of heads when flipping n p-biased coins. 2 αi Proof: Let Xi be an indicator for Ci being heads. Then E(Xi) = p = n2 . Then using the Chernoff 2 2 P −Cαi bound we get P( Xi > e × n × p) ≤ e n 2 Amortization 2.1 Definition If a data structure supports operations A1;A2; :::; Ar, we say that the amortized cost of Aj is tj if r P 8 sequences of operations with ni operations of type Ai the total runtime is ≤ njtj. j=1 2.2 Potential function: Let Φ map the states of the data structures to R>0(the non-negative real numbers), and Φ of the empty data structure is defined to be 0. Then the valid amortized cost of an operation tactual+∆Φ = tactual + Φ(after op) − Φ(before op) R P Then the total amortized cost of a sequence of ops = tactual(j) + Φ(time j) − Φ(timej − 1) = j=1 P (actual time for jth operation) + Φ(final) − Φ0. Since Φ0 = 0 and Φfinal ≥ 0 then our equation j above for total amortized cost is ≥ the total actual time. 2.3 Y-fast Tries n Recall from the first lecture that a Y fast trie consisted of an x-fast trie of θ(w) groups each pointing w to a BJT of [ 2 ; 2w) elements, and we said this supports query of θ(log w) and an amortized insert time of θ(log w). From now on, let t refer to actual time and t~ refers to amortized time. Now lets analyze the Y-fast trie insertion using our potential function. We have Φ(State of the structure) = P ((Size of group j) - w) grps For the query operation we get t~query = tquery + ∆Φ = t~query = tquery + 0 = Θ(log w). For t~insert = tinsert + ∆Φ. Now consider the two cases (either we have to split a group of 2w into 2 groups of size w or we don't). In the first case tinsert = Θ(log w) + w and ∆Φ = −w giving t~insert is Θ(log w). In the second case tinsert = Θ(log w) and ∆Φ = 1 giving t~insert = Θ(log w). 3 Heaps: 3.1 Definition: Heaps maintain keys with comparable values subject to the follow operations: 3 1. deleteMin(): report the smallest item and delete it from the heap 2. decKey(*P, v'): reduce value of p to V' 3. insert(K, V): insert key K with value V to the heap Binary Heaps: John Williams '64 [4] published the binary heap which supports tI (insertion time) = tD (delete min) = tK (dec key) in O(log n). Binomial Heaps: Vuillemin '78 [5] published the Binomial Heap which supports t~I = O(1) and tD = tK = O(log n). Fibonacci Heaps: Fredman and Tarjan '87 [6] published the Fibonacci Heap T~I = T~K = O(1), and tD = O(log n). Strict Fibonacci Heaps: Brodal, Lagogiannis, and Tarjan '12 [7] published the Strict Fibonacci Heap TI = TK = O(1), and tD = O(log n). Then Thorup '07 [8] showed that in Word RAM sorting in nS(n) ) there exists a heap with O(1) find min (note this is not the same as delete min, and O(S(n)) insert/deletep time.
Recommended publications
  • An Alternative to Fibonacci Heaps with Worst Case Rather Than Amortized Time Bounds∗
    Relaxed Fibonacci heaps: An alternative to Fibonacci heaps with worst case rather than amortized time bounds¤ Chandrasekhar Boyapati C. Pandu Rangan Department of Computer Science and Engineering Indian Institute of Technology, Madras 600036, India Email: [email protected] November 1995 Abstract We present a new data structure called relaxed Fibonacci heaps for implementing priority queues on a RAM. Relaxed Fibonacci heaps support the operations find minimum, insert, decrease key and meld, each in O(1) worst case time and delete and delete min in O(log n) worst case time. Introduction The implementation of priority queues is a classical problem in data structures. Priority queues find applications in a variety of network problems like single source shortest paths, all pairs shortest paths, minimum spanning tree, weighted bipartite matching etc. [1] [2] [3] [4] [5] In the amortized sense, the best performance is achieved by the well known Fibonacci heaps. They support delete and delete min in amortized O(log n) time and find min, insert, decrease key and meld in amortized constant time. Fast meldable priority queues described in [1] achieve all the above time bounds in worst case rather than amortized time, except for the decrease key operation which takes O(log n) worst case time. On the other hand, relaxed heaps described in [2] achieve in the worst case all the time bounds of the Fi- bonacci heaps except for the meld operation, which takes O(log n) worst case ¤Please see Errata at the end of the paper. 1 time. The problem that was posed in [1] was to consider if it is possible to support both decrease key and meld simultaneously in constant worst case time.
    [Show full text]
  • Advanced Data Structures
    Advanced Data Structures PETER BRASS City College of New York CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.cambridge.org Information on this title: www.cambridge.org/9780521880374 © Peter Brass 2008 This publication is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2008 ISBN-13 978-0-511-43685-7 eBook (EBL) ISBN-13 978-0-521-88037-4 hardback Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. Contents Preface page xi 1 Elementary Structures 1 1.1 Stack 1 1.2 Queue 8 1.3 Double-Ended Queue 16 1.4 Dynamical Allocation of Nodes 16 1.5 Shadow Copies of Array-Based Structures 18 2 Search Trees 23 2.1 Two Models of Search Trees 23 2.2 General Properties and Transformations 26 2.3 Height of a Search Tree 29 2.4 Basic Find, Insert, and Delete 31 2.5ReturningfromLeaftoRoot35 2.6 Dealing with Nonunique Keys 37 2.7 Queries for the Keys in an Interval 38 2.8 Building Optimal Search Trees 40 2.9 Converting Trees into Lists 47 2.10
    [Show full text]
  • Introduction to Algorithms and Data Structures
    Introduction to Algorithms and Data Structures Markus Bläser Saarland University Draft—Thursday 22, 2015 and forever Contents 1 Introduction 1 1.1 Binary search . .1 1.2 Machine model . .3 1.3 Asymptotic growth of functions . .5 1.4 Running time analysis . .7 1.4.1 On foot . .7 1.4.2 By solving recurrences . .8 2 Sorting 11 2.1 Selection-sort . 11 2.2 Merge sort . 13 3 More sorting procedures 16 3.1 Heap sort . 16 3.1.1 Heaps . 16 3.1.2 Establishing the Heap property . 18 3.1.3 Building a heap from scratch . 19 3.1.4 Heap sort . 20 3.2 Quick sort . 21 4 Selection problems 23 4.1 Lower bounds . 23 4.1.1 Sorting . 25 4.1.2 Minimum selection . 27 4.2 Upper bounds for selecting the median . 27 5 Elementary data structures 30 5.1 Stacks . 30 5.2 Queues . 31 5.3 Linked lists . 33 6 Binary search trees 36 6.1 Searching . 38 6.2 Minimum and maximum . 39 6.3 Successor and predecessor . 39 6.4 Insertion and deletion . 40 i ii CONTENTS 7 AVL trees 44 7.1 Bounds on the height . 45 7.2 Restoring the AVL tree property . 46 7.2.1 Rotations . 46 7.2.2 Insertion . 46 7.2.3 Deletion . 49 8 Binomial Heaps 52 8.1 Binomial trees . 52 8.2 Binomial heaps . 54 8.3 Operations . 55 8.3.1 Make heap . 55 8.3.2 Minimum . 55 8.3.3 Union . 56 8.3.4 Insert .
    [Show full text]
  • Data Structures and Programming Spring 2016, Final Exam
    Data Structures and Programming Spring 2016, Final Exam. June 21, 2016 1 1. (15 pts) True or False? (Mark for True; × for False. Score = maxf0, Right - 2 Wrongg. No explanations are needed. (1) Let A1;A2, and A3 be three sorted arrays of n real numbers (all distinct). In the comparison model, constructing a balanced binary search tree of the set A1 [ A2 [ A3 requires Ω(n log n) time. × False (Merge A1;A2;A3 in linear time; then pick recursively the middle as root (in linear time).) (2) Let T be a complete binary tree with n nodes. Finding a path from the root of T to a given vertex v 2 T using breadth-first search takes O(log n) time. × False (Note that the tree is NOT a search tree.) (3) Given an unsorted array A[1:::n] of n integers, building a max-heap out of the elements of A can be performed asymptotically faster than building a red-black tree out of the elements of A. True (O(n) for building a max-heap; Ω(n log n) for building a red-black tree.) (4) In the worst case, a red-black tree insertion requires O(1) rotations. True (See class notes) (5) In the worst case, a red-black tree deletion requires O(1) node recolorings. × False (See class notes) (6) Building a binomial heap from an unsorted array A[1:::n] takes O(n) time. True (See class notes) (7) Insertion into an AVL tree asymptotically beats insertion into an AA-tree. × False (See class notes) (8) The subtree of the root of a red-black tree is always itself a red-black tree.
    [Show full text]
  • Data Structures Binary Trees and Their Balances Heaps Tries B-Trees
    Data Structures Tries Separated chains ≡ just linked lists for each bucket. P [one list of size exactly l] = s(1=m)l(1 − 1=m)n−l. Since this is a Note: Strange structure due to finals topics. Will improve later. Compressing dictionary structure in a tree. General tries can grow l P based on the dictionary, and quite fast. Long paths are inefficient, binomial distribution, easily E[chain length] = (lP [len = l]) = α. Binary trees and their balances so we define compressed tries, which are tries with no non-splitting Expected maximum list length vertices. Initialization O(Σl) for uncompressed tries, O(l + Σ) for compressed (we are only making one initialization of a vertex { the X s j AVL trees P [max len(j) ≥ j) ≤ P [len(i) ≥ j] ≤ m (1=m) last one). i j i Vertices contain -1,0,+1 { difference of balances between the left and T:Assuming all l-length sequences come with uniform probability and we have a sampling of size n, E[c − trie size] = log d. j−1 the right subtree. Balance is just the maximum depth of the subtree. k Q (s − k) P = k=0 (1=m)j−1 ≤ s(s=m)j−1=j!: Analysis: prove by induction that for depth k, there are between Fk P:qd ≡ probability trie has depth d. E[c − triesize] = d d(qd − j! k P and 2 vertices in every tree. Since balance only shifts by 1, it's pretty qd+1) = d qd. simple. Calculate opposite event { trie is within depth d − 1.
    [Show full text]
  • Chapter C4: Heaps and Binomial / Fibonacci Heaps
    Chapter C4: Heaps and Binomial / Fibonacci Heaps C4.1 Heaps A heap is the standard implementation of a priority queue. A min-heap stores values in nodes of a tree such that heap-order property: for each node, its value is smaller than or equal to its children’s So the minimum is on top. (A max-heap can be defined similarly.) The standard heap uses a binary tree. Specifically, it uses a complete binary tree, which we define here to be a binary tree where each level except the last is full, and in the last level nodes are added left to right. Here is an example: 7 24 19 25 56 68 40 29 31 58 Now, any binary tree can be stored in an array using level numbering. The root is in cell 0, cells 1 and cells 2 are for its children, cells 3 through 6 are for its grandchildren, and so on. Note that this means a nice formula: if a node is in cell x,thenitschildren are in 2x+1 and 2x+2. Such storage can be (very) wasteful for a general binary tree; but the definition of complete binary tree means the standard heap is stored in consecutive cells of the array. C4.2 Heap Operations The idea for insertion is to: Add as last leaf, then bubble up value until heap-order property re-established. Insert(v) add v as next leaf while v<parent(v) { swapElements(v,parent(v)) v=parent(v) } One uses a “hole” to reduce data movement. Here is an example of inserting the value 12: 7 7 24 19 12 19 ) 25 56 68 40 25 24 68 40 29 31 58 12 29 31 58 56 The idea for extractMin is to: Replace with value from last leaf, delete last leaf, and bubble down value until heap-order property re-established.
    [Show full text]
  • Lecture Notes of CSCI5610 Advanced Data Structures
    Lecture Notes of CSCI5610 Advanced Data Structures Yufei Tao Department of Computer Science and Engineering Chinese University of Hong Kong July 17, 2020 Contents 1 Course Overview and Computation Models 4 2 The Binary Search Tree and the 2-3 Tree 7 2.1 The binary search tree . .7 2.2 The 2-3 tree . .9 2.3 Remarks . 13 3 Structures for Intervals 15 3.1 The interval tree . 15 3.2 The segment tree . 17 3.3 Remarks . 18 4 Structures for Points 20 4.1 The kd-tree . 20 4.2 A bootstrapping lemma . 22 4.3 The priority search tree . 24 4.4 The range tree . 27 4.5 Another range tree with better query time . 29 4.6 Pointer-machine structures . 30 4.7 Remarks . 31 5 Logarithmic Method and Global Rebuilding 33 5.1 Amortized update cost . 33 5.2 Decomposable problems . 34 5.3 The logarithmic method . 34 5.4 Fully dynamic kd-trees with global rebuilding . 37 5.5 Remarks . 39 6 Weight Balancing 41 6.1 BB[α]-trees . 41 6.2 Insertion . 42 6.3 Deletion . 42 6.4 Amortized analysis . 42 6.5 Dynamization with weight balancing . 43 6.6 Remarks . 44 1 CONTENTS 2 7 Partial Persistence 47 7.1 The potential method . 47 7.2 Partially persistent BST . 48 7.3 General pointer-machine structures . 52 7.4 Remarks . 52 8 Dynamic Perfect Hashing 54 8.1 Two random graph results . 54 8.2 Cuckoo hashing . 55 8.3 Analysis . 58 8.4 Remarks . 59 9 Binomial and Fibonacci Heaps 61 9.1 The binomial heap .
    [Show full text]
  • Problem Set 2 1 Lazy Binomial Heaps (100 Pts)
    ICS 621: Analysis of Algorithms Fall 2019 Problem Set 2 Prof. Nodari Sitchinava Due: Friday, September 20, 2019 at the start of class You may discuss the problems with your classmates, however you must write up the solutions on your own and list the names of every person with whom you discussed each problem. 1 Lazy Binomial Heaps (100 pts) Being lazy is nothing to be proud of, but occasionally it can improve the overall execution. In this exercise, we will see how delaying the work of the Union operation in the binomial heap can improve the runtime of several operations of the binomial heap. Delete and Decrease-Key operations in the lazy binomial heap will remain unchanged. To implement the new Union we will store the list of roots as a circular doubly-linked list. That is, every node in the linked list has two pointers left and right, including the head and the tail of the list, such that head:left = tail and tail:right = head: We will also maintain the number of elements stored in the heap as a field Q:n (accessible in O(1) time). Consider the following description of Union(Q1;Q2). It simply appends the root list of Q2 to the right of the root list of Q1: function Union(Q1, Q2) if Q1:head = NIL return Q2 else if Q2:head 6= NIL tail1 Q1:head:left; tail2 Q2:head:left . Pointers to the tails of Q1 and Q2 Q2:head:left tail1; tail1:right Q2:head . Link head of Q2 to the right of the tail of Q1 Q1:head:left tail2 ; tail2:right Q1:head .
    [Show full text]
  • Part C: Data Structures Wayne Goddard, School of Computing, Clemson University, 2019
    Part C: Data Structures Wayne Goddard, School of Computing, Clemson University, 2019 Data Structures 1 C1.1 Basic Collections . 1 C1.2 Stacks and Queues . 1 C1.3 Dictionary . 2 C1.4 Priority Queue . 2 Skip Lists 3 C2.1 Levels . 3 C2.2 Implementation of Insertion . 3 Binary Search Trees 5 C3.1 Binary Search Trees . 5 C3.2 Insertion and Deletion in BST . 5 C3.3 Rotations . 6 C3.4 AVL Trees . 6 Heaps and Binomial / Fibonacci Heaps 9 C4.1 Heaps . 9 C4.2 Heap Operations . 9 C4.3 Binomial Heaps . 11 C4.4 Decrease-Key and Fibonacci Heaps . 12 Hash Tables 14 C5.1 Buckets and Hash Functions . 14 C5.2 Collision Resolution . 14 C5.3 Rehashing . 15 C5.4 Other Applications of Hashing . 16 Disjoint Set Data Structure 17 C6.1 Disjoint Forests . 17 C6.2 Pointer Jumping . 18 Chapter C1: Data Structures An ADT or abstract data type defines a way of interacting with data: it specifies only how the ADT can be used and says nothing about the implementation of the structure. An ADT is conceptually more abstract than a Java interface specification or C++ list of class member function prototypes, and should be expressed in some formal language (such as mathematics). A data structure is a way of storing data that implements certain operations. When choosing a data structure for your ADT, you might consider many issues such as whether the data is static or dynamic, whether the deletion operation is important, whether the data is ordered, etc. C1.1 Basic Collections There are three basic collections.
    [Show full text]
  • 18.415 Advanced Algorithms Contents
    18.415 Advanced Algorithms Notes from Fall 2020. Last Updated: November 27, 2020. Contents Introduction 6 1 Lecture 1: Fibonacci Heaps7 1.1 MST problem review.................................7 1.2 Using d-heaps for MST................................8 1.3 Introduction to Fibonacci Heaps...........................8 2 Lecture 2: Fibonacci Heaps, Persistent Data Structs 12 2.1 Fibonacci Heaps Continued.............................. 12 2.2 Applications of Fibonacci Heaps........................... 14 2.2.1 Further Improvements............................ 15 2.3 Introduction to Persistent Data Structures...................... 15 3 Lecture 3: Persistent Data Structs, Splay Trees 16 3.1 Persistent Data Structures Continued........................ 16 3.2 The Planar Point Location Problem......................... 17 3.3 Introduction to Splay Trees.............................. 19 4 Lecture 4: Splay Trees 20 4.1 Heuristics of Splay Trees............................... 20 4.2 Solving the Balancing Problem............................ 20 4.3 Implementation and Analysis of Operations..................... 21 4.4 Results with the Access Lemma........................... 23 5 Lecture 5: Splay Updates, Buckets 25 5.1 Wrapping up Splay Trees............................... 25 5.2 Buckets and Indirect Addressing........................... 26 5.2.1 Improvements................................. 27 5.2.2 Formalization with Tries........................... 27 5.2.3 Laziness wins again.............................. 28 1 6 Lecture 6: VEB queues, Hashing 29 6.1 Improvements
    [Show full text]
  • Binomal Heaps and Queues Node
    EECS 311: Data Structure and Data Management Lecture 21, 22 Binomial Queues Binomial Queues & Heaps Reading: Chapter 6 (except 6.4–6.7); Chap- binomial tree structure: ter 11, Sections 2 and 4. • n is power of 2. • n = 1: binomial tree is a single Binomal Heaps and Queues node. • n =2i two 2i−1 node binomial trees, binary heaps based queues may be improv- make one a child of root of other. able. Example: 1. perform some operations faster? • One node trees: 2. binomial queue 2 . 9 • O(log n) merge. • Two node trees: 3. redundant binomial queue 2 5 • O(1) insert 9 7 • Θ(log n) delete-min, reduce-key. • Four node trees: 4. Fibonacci heaps 2 1 • O(1) insert, reduce-key 9 5 6 3 • O(log n) delete-min 7 8 • Dijkstra’s shortest paths + fi- conacci heap ⇒ Θ(n log n + m). • Eight node tree: Binomial Heaps 1 Def: a binomial heaps is a tree that satis- 6 3 2 fies 8 9 5 heap order: key at node is smaller than keys of children. 7 1 Def: a binomial queue is 1. make k into single-node queue Q′. ′ • a list of binomial heaps. 2. merge Q and Q . • for each i, at most one heap of size 2i. Runtime: merge = Θ(log n) Algorithm: delete-min Algorithm: binomial heap merge Input: Q Input: H1 and H2, two n node binomial i heaps. 1. find heap with min key ⇒ Hi, size 2 ′ • Make tree with greater root-key child of 2. remove heap Hi ⇒ Q root of other tree.
    [Show full text]
  • FIBONACCI HEAPS ‣ Preliminaries ‣ Insert ‣ Extract the Minimum
    Priority queues performance cost summary FIBONACCI HEAPS operation linked list binary heap binomial heap Fibonacci heap † MAKE-HEAP O(1) O(1) O(1) O(1) ‣ preliminaries IS-EMPTY O(1) O(1) O(1) O(1) ‣ insert INSERT O(1) O(log n) O(log n) O(1) ‣ extract the minimum EXTRACT-MIN O(n) O(log n) O(log n) O(log n) ‣ decrease key DECREASE-KEY O(1) O(log n) O(log n) O(1) ‣ bounding the rank ‣ meld and delete DELETE O(1) O(log n) O(log n) O(log n) MELD O(1) O(n) O(log n) O(1) Lecture slides by Kevin Wayne FIND-MIN O(n) O(1) O(log n) O(1) http://www.cs.princeton.edu/~wayne/kleinberg-tardos † amortized Ahead. O(1) INSERT and DECREASE-KEY, O(log n) EXTRACT-MIN. Last updated on Apr 15, 2013 6:59 AM 2 Fibonacci heaps Fibonacci heaps Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap, Theorem. [Fredman-Tarjan 1986] Starting from an empty Fibonacci heap, any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operations any sequence of m INSERT, EXTRACT-MIN, and DECREASE-KEY operations involving n INSERT operations takes O(m + n log n) time. involving n INSERT operations takes O(m + n log n) time. this statement is a bit weaker than the actual theorem History. Fibonacci Heaps and Their Uses in Improved Network ・Ingenious data structure and application of amortized analysis. Optimization Algorithms ・Original motivation: improve Dijkstra's shortest path algorithm MICHAEL L.
    [Show full text]