Data structures Binomial Heaps - Binomial Trees B0B0 BkBk B k-1.

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

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)
Advanced Data structure
Fibonacci Heaps CS 252: Algorithms Geetika Tewari 252a-al Smith College December, 2000.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
© 2004 Goodrich, Tamassia Priority Queues1 Heaps: Tree-based Implementation of a Priority Queue.
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Priority Queue Sorting (§ 8.1.4) We can use a priority queue to sort a set.
Binomial Heaps. Min Binomial Heap Collection of min trees
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.
Fibonacci Heaps. Single Source All Destinations Shortest Paths
Priority Queues. Container of elements where each element has an associated key A key is an attribute that can identify rank or weight of an element Examples.
Fibonacci Heap.
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.
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
1 Priority Queues CPS212 Gordon College VIP. 2 Introduction to STL Priority Queues Adaptor container - underlying container may be either: – a template.
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.
Heaps and Priority Queues Priority Queue ADT (§ 2.4.1) A priority queue stores a collection of items An item is a pair (key, element) Main.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Binary and Binomial Heaps These lecture slides are adapted from CLRS, Chapters.
Fundamental Structures of Computer Science March 02, 2006 Ananda Guna Binomial Heaps.
1 Binomial heaps, Fibonacci heaps, and applications.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
Binomial Heaps Melalite Ayenew Dec 14, 2000.
Binomial Heaps Referred to “MIT Press: Introduction to Algorithms 2 nd Edition”
§8 Binomial Queues Haven’t we had enough about queues? What is a binomial queue for? Well, what is the average time for insertions with leftist or skew.
Binomial Queues Text Read Weiss, §6.8 Binomial Queue Definition of binomial queue Definition of binary addition Building a Binomial Queue Sequence of inserts.
Lecture X Fibonacci Heaps
CS 473Lecture X1 CS473-Algorithms Lecture BINOMIAL HEAPS.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
Chapter 19: Fibonacci Heap Many of the slides are from Prof. Leong Hon Wai’s resources at National University of Singapore.
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Binomial Tree B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4 Adapted from: Kevin Wayne B k : a binomial tree B k-1 with the addition of a left child with another.
CMSC 341 Binomial Queues and Fibonacci Heaps. Basic Heap Operations OpBinary Heap Leftist Heap Binomial Queue Fibonacci Heap insertO(lgN) deleteMinO(lgN)
Mergeable Heaps David Kauchak cs302 Spring Admin Homework 7?
Priority Queues CS 110: Data Structures and Algorithms First Semester,
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Data structures What does that mean? In general there are two aspects: how data will be organized in computer memory what will be the operations that will.
Fibonacci Heaps.
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 Heap. p2. Procedure Binary heap (worst-case) Fibonacci heap (amortized) MAKE-HEAP  (1) INSERT  (lg n)  (1) MINIMUM  (1) EXTRACT-MIN  (lg.
Priority Queues CS /02/05 L7: PQs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
Fibonacci Heap Fibonacci heapshave better asymptotic time bounds than binary heaps for the INSERT, UNION, and DECREASE-KEY operations, and they.
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))
Analysis of Algorithms
Binomial heaps, Fibonacci heaps, and applications
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
What does that mean? In general there are two aspects:
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Bohyung Han CSE, POSTECH
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Binomial Heaps Chapter 19.
Binomial Tree Adapted from: Kevin Wayne Bk-1 B0 Bk
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Binomial Heap.
Chapter 20 Binomial Heaps
Fibonacci Heap.
ערמות בינומיות ופיבונצ'י
CS 583 Analysis of Algorithms
Fundamental Structures of Computer Science
CS 583 Analysis of Algorithms
21장. Fibonacci Heaps 숭실대학교 인공지능 연구실 석사 2학기 김완섭.
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Binomial heaps, Fibonacci heaps, and applications
Fibonacci Heaps.
Binomial heaps, Fibonacci heaps, and applications
Heaps 9/29/2019 5:43 PM Heaps Heaps.
Presentation transcript:

Data structures Binomial Heaps - Binomial Trees B0B0 BkBk B k-1

Data structures Binomial Heaps - Binomial Trees B0B0 B2B2 B1B1 B3B3

Data structures Binomial Heaps - Binomial Trees B4B4

Data structures Binomial Heaps - Binomial Trees BkBk B k-1 B k-2 B2B2 B1B1 B0B0 

Data structures Binomial Heaps - Binomial Trees Properties of binomial tree B k it has 2 k nodes the height of the tree is k it has exactly C k i nodes at depth i for i = 0, 1, , k C k i = n ! / (i ! (n – i) !) the root has degree k

Data structures Binomial Heaps - Definition Binomial heap H is an ordered list of binomial trees that satisfies the following properties: Each binomial tree is heap-ordered, i.e. for each node its key is greater or equal to the key of its parent There is at most one binomial tree in H whose root has a given degree Binomial trees are contained in the list in the order of increasing degrees

Data structures Binomial Heaps - Example

Data structures Binomial Heaps - Example KeyDataDegParentLeftNext

Data structures Binomial Heaps - Example [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Binomial Heaps - Min procedure Min(BinomialHeap H): min   P  H.Head while P  0 do if P.Key < min then min  P.Key P  P.Next return min

Data structures Binomial Heaps - Union - Example H1H1 H2H2

Data structures Binomial Heaps - Union - Example H1H2H1H2

Data structures Binomial Heaps - Union - Example H1H2H1H2

Data structures Binomial Heaps - Union - Example H1H2H1H2

Data structures Binomial Heaps - Union - Example H1H2H1H2

Data structures Binomial Heaps - Union procedure Union(BinomialHeap H1,H2): H  BinomialHeapMakeEmpty() P  H.Head; P1  H1.Head; P2  H2.Head while P1  0 and P2  0 do if P1.Deg < P2.Deg then P.Next  P1; P1  P1.Next else P.Next  P2; P2  P2.Next while P1  0 do P.Next  P1; P1  P1.Next while P2  0 do P.Next  P2; P2  P2.Next

Data structures Binomial Heaps - Union [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Binomial Heaps - Union (continued) P1  H.Head; P2  P1; P3  P1; P4  P1 merge  0 while P1.Next  0 do P4  P3; P3  P2; P2  P1; P1  P1.Next if P1.Deg = P2.Deg then merge  1 if P1.Deg < P2.Deg and merge = 1 then if P2.Key < P3.Key then P2  P3 if P4 = H.Head then H.Head  P3 else P4.Next  P3 P2.Next  P3.Left; P2.Parent  P3 P3.Left  P2; P3.Next  P1; P3.Deg  P3.Deg + 1 merge  0 return H

Data structures Binomial Heaps - Insert procedure Insert(BinomialHeap H, int Key, int Data): H1  BinomialHeapMakeEmpty() E  NewNode() H1.Head  E; E.Next  0 E.Parent  0; E.Left  0 E.Deg  0 E.Key  Key; E.Data  Data; H  Union(H,H1)

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin - Example

Data structures Binomial Heaps - ExtractMin procedure ExtractMin(BinomialHeap H): min   ; M  0; MP  0 P  H.Head; PP  H.Head while P  0 do if P.Key < min then min  P.Key; M  P; MP  PP PP  P; P  P.Next if M = 0 then return fail

Data structures Binomial Heaps - ExtractMin (continued) H1  BinomialHeapMakeEmpty() if MP  H.Head then MP.Next  M.Next else H.Head  M.Next P  M.Left while P  0 do Next  P.Next P.Next  H1.Head; H1.Head  P P.Parent  0 P  Next H  Union(H,H1)

Data structures Binomial Heaps - DecreaseKey - Example

Data structures Binomial Heaps - DecreaseKey - Example

Data structures Binomial Heaps - DecreaseKey - Example

Data structures Binomial Heaps - DecreaseKey - Example

Data structures Binomial Heaps - DecreaseKey - Example

Data structures Binomial Heaps - DecreaseKey procedure DecreaseKey(BinomialHeap H, Node P, int Key): Parent  P.Parent while Parent  0 and P.Key < Parent.Key do P.Key  Parent.Key P.Data  Parent.Data P  Parent Parent  Parent.Parent

Data structures Binomial Heaps - Delete procedure DeleteKey(BinomialHeap H, Node P): BinomialHeapDecreaseKey(H,P,   ) BinomialHeapExtractMin(H)

Data structures Binomial Heaps - Summary Binomial HeapsHeaps Min  (log n) or  (1)  (1) ExtractMin  (log n) DecreaseKey  (log n) Union  (log n) (n)(n) Insert  (log n) Delete  (log n) MakeEmpty  (1) IsEmpty  (1)

Data structures Fibonacci Heaps [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Example min(H)

Data structures Fibonacci Heaps - Example min(H) KeyDataDegParentLeftNextPrevious

Data structures Fibonacci Heaps - Example [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Degree and Marked nodes A degree D(x) of a node x in Fibonacci heap is defined as a number of children of node x (unlike as it is for binomial heaps, D(x) may not be equal with height of the tree rooted at x). A node x in Fibonacci Heap is marked if and only if it has lost a child since the last time x was made the child of another node (or since the last time x was made the root)

Data structures Fibonacci Heaps - Min [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Insert [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Insert - Example min(H) 1

Data structures Fibonacci Heaps - Insert - Example min(H) 1

Data structures Fibonacci Heaps - Insert - Example min(H) 1

Data structures Fibonacci Heaps - Union [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - ExtractMin [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - ExtractMin [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - ExtractMin - Example min(H) 21

Data structures Fibonacci Heaps - ExtractMin - Example min(H) 21

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example

Data structures Fibonacci Heaps - ExtractMin - Example min(H)

Data structures Fibonacci Heaps - DecreaseKey [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - DecreaseKey - Example min(H) 15

Data structures Fibonacci Heaps - DecreaseKey - Example min(H)

Data structures Fibonacci Heaps - DecreaseKey - Example min(H) 5

Data structures Fibonacci Heaps - DecreaseKey - Example min(H) 5

Data structures Fibonacci Heaps - DecreaseKey - Example min(H) 5

Data structures Fibonacci Heaps - DecreaseKey - Example min(H) 5

Data structures Fibonacci Heaps - Delete [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Complexity Heap potential P(H) = t(H) + 2m(H), where t(H) - number of nodes in root level, m(H) - number of marked nodes. Amortised complexity T a (H) = T(H) +  P(H)

Data structures Fibonacci Heaps - Complexity Insert Min [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Complexity Union [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Complexity ExtractMin [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Complexity DecreaseKey Delete - just sum of the costs for DecreaseKey and ExtractMin [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Degree and size D(n) - maximal possible node degree in Fibonacci heap with n elements Theorem D(n) =  (log n)

Data structures Fibonacci Heaps - Degree and size Observation If only operations Min,Union, Insert, ExtractMin, MakeEmpty and IsEmpty are used, then the resulting Fibonacci heap is just a collection of unordered Binomial trees, thus D(n) =  (log n).

Data structures Fibonacci Heaps - Degree and size Lemma Let x be a node in a Fibonacci heap with degree(x) = k. Let y 1,..., y k be the children of x in the order in which they were linked to x, from the earliest to the latest. Then degree(y 1 )  0 and degree(y i )  i – 2 for i = 2, 3,..., k. [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Degree and size Fibonacci numbers F 0 = 0F 1 = 1F k = F k – 1 + F k – 2 Lemma For all k  0: F k + 2 = 1 +  i = 0...k F i

Data structures Fibonacci Heaps - Degree and size Lemma Let x be a node in a Fibonacci heap and let degree(x) = k. Then size(x)  F k + 2   k, where  k = (1 +  5)/2. [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Degree and size [Adapted from T.Cormen, C.Leiserson, R. Rivest]

Data structures Fibonacci Heaps - Degree and size Corollary The maximum degree D(n) of any node in an n-node Fibonacci heap is O(log n).

Data structures Fibonacci Heaps - Summary Fibonacci Heaps Binomial HeapsHeaps Min  (1)  (log n) or  (1)  (1) ExtractMin  (log n) DecreaseKey  (1)  (log n) Union  (1)  (log n) (n)(n) Insert  (1)  (log n) Delete  (log n) MakeEmpty  (1) IsEmpty  (1)