Chapter 20 Binomial Heaps

Slides:



Advertisements
Similar presentations
Binomial Heaps. Heap Under most circumstances you would use a “normal” binary heap Except some algorithms that may use heaps might require a “Union” operation.
Advertisements

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.
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)
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Jan Binary Search Trees What is a search binary tree? Inorder search of a binary search tree Find Min & Max Predecessor and successor BST insertion.
Analysis of Algorithms CS 477/677 Binary Search Trees Instructor: George Bebis (Appendix B5.2, Chapter 12)
Binary Search Trees Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture six Dr. Hamdy M. Mousa.
David Luebke 1 5/4/2015 Binary Search Trees. David Luebke 2 5/4/2015 Dynamic Sets ● Want a data structure for dynamic sets ■ Elements have a key and satellite.
Binary Search Trees Comp 550.
CS 315 March 24 Goals: Heap (Chapter 6) priority queue definition of a heap Algorithms for Insert DeleteMin percolate-down Build-heap.
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.
1.1 Data Structure and Algorithm Lecture 12 Binary Search Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Binary Search Trees.
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.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Binary and Binomial Heaps These lecture slides are adapted from CLRS, Chapters.
Binomial Heaps Melalite Ayenew Dec 14, 2000.
Franklin University 1 COMP 620 Algorithm Analysis Module 3: Advanced Data Structures Trees, Heap, Binomial Heap, Fibonacci Heap.
Binomial Heaps Referred to “MIT Press: Introduction to Algorithms 2 nd Edition”
Chapter 21 Priority Queue: Binary Heap Saurav Karmakar.
Lecture X Fibonacci Heaps
CS 473Lecture X1 CS473-Algorithms Lecture BINOMIAL HEAPS.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
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.
1 Algorithms CSCI 235, Fall 2015 Lecture 22 Binary Search Trees.
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.
Lecture 19. Binary Search Tree 1. Recap Tree is a non linear data structure to present data in hierarchical form. It is also called acyclic data structure.
Fundamentals of Algorithms MCS - 2 Lecture # 17. Binary Search Trees.
Fibonacci Heaps.
1 Chapter 6 Heapsort. 2 About this lecture Introduce Heap – Shape Property and Heap Property – Heap Operations Heapsort: Use Heap to Sort Fixing heap.
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
Binary Search Trees What is a binary search tree?
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
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,
Analysis of Algorithms
Bohyung Han CSE, POSTECH
CS 583 Analysis of Algorithms
Data Structures – Week #8
Lecture 7 Algorithm Analysis
Binomial Heaps Chapter 19.
Binomial Tree Adapted from: Kevin Wayne Bk-1 B0 Bk
Red-Black Trees.
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
© 2013 Goodrich, Tamassia, Goldwasser
Binomial Heap.
Fibonacci Heap.
ערמות בינומיות ופיבונצ'י
CS 583 Analysis of Algorithms
Fundamental Structures of Computer Science
Binary Search Trees (13.1/12.1)
Lecture 7 Algorithm Analysis
Algorithms and Data Structures Lecture VII
Chapter 12: Binary Search Trees
CS 583 Analysis of Algorithms
CS6045: Advanced Algorithms
Lecture 7 Algorithm Analysis
21장. Fibonacci Heaps 숭실대학교 인공지능 연구실 석사 2학기 김완섭.
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Topic 6: Binary Search Tree Data structure Operations
Binary and Binomial Heaps
Design and Analysis of Algorithms
Fibonacci Heaps.
Data Structures – Week #8
Priority Queues Supports the following operations. Insert element x.
Analysis of Algorithms CS 477/677
Binary Search Trees Comp 122, Spring 2004.
Chapter 12&13: Binary Search Trees (BSTs)
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

Chapter 20 Binomial Heaps 컴퓨터 알고리즘 인공지능연구실 민병국 2000. 12. 1

Preface Binomial Heap introduced in 1978 by Jean Vuillemin “A data structure for manipulating priority queues” communications of the ACM, 21(4):309-315 studied their properties in detail by Mark R. Brown “The Analysis of a Practical and Nearly Optimal Priority Queue” “Implementation and analysis of binomial queue algorithms”

Preface Mergeable Heaps +  Binomial coefficients binomial expansion : +  Binomial coefficients binomial expansion : x=y=1 : ex) n=4  24 = ( 1 + 4 + 6 + 4 + 1 ) Bk-1 Bk-1 Bk-1 Bk-1 Bk

Mergeable Heaps Five operations Make-Heap() Insert(H,x) Minimum(H) Heap H에 Node x 삽입 Minimum(H) Heap H의 가장 작은 Key의 Pointer 반환 Extract-Min(H) 가장 작은 Key의 Node를 빼 냄 Union(H1, H2) Heap H1, H2를 병합, 새로운 Heap 생성

Mergeable Heaps Additional two operation in Binomial heaps Decrease-Key(H, x, k) Heap H의 Node x의 키값을 그 이하의 값 k로 대입 Delete(H,x) Heap H로부터 Node x를 제거

Running times for operations Binary Binomial Fibonacci Procedure heap heap heap Make-Heap Insert Minimum Extract-Min Union Decrease-Key Delete

Figure 20.2 Binomial trees (a) B0 (b) B0 B1 B2 B3 B4 (c) Depth 1 2 3 4 1 2 3 4 B0 Bk-1 Bk Bk-1 (b) B0 B1 B2 B3 B4 (c) B0 B1 B2 Bk Bk-2 Bk-1

Binomial trees Lemma 20.1(Properties of binomial trees) For the binomial tree Bk, 1.There are 2k nodes Binomial tree Bk consists of two copies of Bk-1, so Bk has 2k-1+ 2k-1 = 2k noes 2.The height of the tree is k Because the maximum depth of a node in Bk is one greater than the maximum depth in Bk-1, this maximum depth is (k-1)+1=k

Binomial trees 3.There are exactly nodes at depth i for i=0,1,…,k Let D(k,i) be the number of nodes at depth i of binomial tree Bk D(k,i) = D(k-1,i) + D(k-1,i-1) = ※ k-combinations of an n-set

Binomial trees 4.The root has degree k, which is greater than that of any other node; moreover if the children of the root are numbered from left to right by k-1,k-2,…,0, child i is the root of a subtree Bi The only node with greater degree in Bk than in Bk-1 is the root, which has one more child than in Bk-1 Bk = Bk-1 + Bk-1 Bk = Bk-1 + (Bk-2 + Bk-3 + … + B0 ) Therefore, the root of Bk has Bk-1, Bk-2, … , B1, B0.

Figure 20.3 Binomial heap (a) head[H] 10 1 25 12 18 6 29 14 8 38 17 11 27

Figure 20.3 Binomial heap (b) head[H] p key degree child 10 1 2 25 12 1 2 25 12 18 6 3 29 38 14 8 17 11 27 head[H] sibling (b)

Binomial heaps Binomial heap H is a set of binomial trees that satisfies the following properties. Binomial-heap properties 1. Each binomial tree in H is heap-ordered: the key of a node is greater than or equal to the key of its parent. The root of a heap-ordered tree contains the smallest key in the tree

Binomial Heaps 2. There is at most one binomial tree in H whose root has a given degree. An n-node binomial heap H consists of at most binomial trees. The binary representation of n has bits, say , so that ex) the binary representation of 13 is <1101>  H consists of heap-ordered binomial trees B3, B2, and B0, having 8, 4, and 1 nodes respectively, for a total of 13 nodes

Operations on binomial heaps Creating a new binomial heap Finding the minimum key Uniting two binomial heaps Inserting a node Extracting the node with minimum key Decreasing a key Deleting a key

Creating a new binomial heap Allocates and returns an object H head[H] = Nil running time is

Finding the minimum key Binomial-Heap-Minimum(H) y  Nil x  head[H] min  ∞ while x ≠ Nil do if key[x] < min then min  key[x] y  x x  sibling[x] return y running time is Since a binomial heap is heap-ordered, the minimum key must reside in a root node: at most

Uniting two binomial heaps Binomial-Link(y,z) : running time is O(1) p[y]  z sibling[y]  child[z] child[z]  y degree[z]  degree[z] + 1 Binomial-Heap-Merge(H1,H2) merges the root lists of H1 and H2 into a single linked list that is sorted by degree into monotonically increasing order. If the root lists of H1 and H2 have m roots altogether, running time is O(m) The running time of Binomial-Heap-Union is

Figure 20.6 Four cases In each case, x is the root of a Bk-tree and l > k (a) Case 1: degree[x]≠degree[next-x] pointers move one position further down the root list (b) Case 2: degree[x]=degree[next-x]=degree[sibling[next-x]] (c) Case 3: degree[x]=degree[next-x]≠ degree[sibling[next-x]] and key[x]≤key[next-x] remove next-x from the root list and link it to x, creating a Bk+1-tree (d) Case 4: degree[x]=degree[next-x]≠ degree[sibling[next-x]] and key[next-x]≤key[x] remove x from the root list and link it to next-x,

Figure 20.5 Binomial-Heap-Union (a) Binomial heaps H1 and H2 (b) case 3: both x and next-x have degree 0 and key[x] < key[next-x] (c) case 2: x is the first of three roots with the same degree (d) case 4: x is the first of two roots of equal degree (e) case 3: both x and next-x have degree 2 (f) case 1: x has degree 3 and next-x has degree 4

Binomial-Heap-Union (1/2) Binomial-Heap-Union(H1,H2) H  Make-Binomial-Heap() head[H]  Binomial-Heap-Merge(H1,H2) free the objects H1 and H2 but not the lists they point to if head[H] = Nil then return H prev-x  Nil x  head[H] next-x  sibling[x] while next-x ≠ Nil

Binomial-Heap-Union (2/2) do if (degree[x] ≠ degree[next-x]) or (sibling[next-x] ≠ Nil and degree[sibling[next-x]] = degree[x]) then prev-x  x ▶ Case 1 and 2 x  next-x ▶ Case 1 and 2 else if key[x] ≤ key[next-x] then sibling[x]  sibling[next-x] ▶ Case 3 Binomial-Link(next-x,x) ▶ Case 3 else if prev-x = Nil ▶ Case 4 then head[H]  next-x ▶ Case 4 else sibling[prev-x]  next-x ▶ Case 4 Binomial-Link(x,next-x) ▶ Case 4 x  next-x ▶ Case 4 next-x  sibling[x] return H

Inserting a node Binomial-Heap-Insert(H,x) Running time is H’  Make-Binomial-Heap() p[x]  Nil child[x]  Nill sibling[x]  Nil degree[x]  0 head[H’]  x H  Binomial-Heap-Union(H,H’) Running time is unites the new heap H’ with the n-node binomial heap H in

Extracting the node with minimum key Binomial-Heap-Extract-Min(H) find the root x with the minimum key in the root list of H, and remove x from the root list of H H’  Make-Binomial-Heap() reverse the order of the linked list of x’s children, and set head[H’] to point to the head of the resulting list H  Binomial-Heap-Union(H,H’) return x Running Time is

Figure 20.7 Binomial-Heap-Extract-Min A binomial heap H The root x with minimum key is removed from the root list of H The linked list of x’s children is reversed, giving another binomial heap H’ The result of uniting H and H’

Decreasing a key Binomial-Heap-Decrease-Key(H,x,k) Running Time is if k > key[x] then error “new key is greater than current key” key[x]  k y  x z  p[y] while z ≠ Nil and key[y] < key[z] do exchange key[y] ↔ key[z] ▷If y and z have satellite fields, exchange them, too. y  z Running Time is becase following the root path, the while loop iterates at most times

Figure 20.8 Binomial-Heap-Decrease-Key The first iteration of the while loop. Node y has had its key decreased to 7, which is less than the key of y’s parent z The keys of the two nodes are exchanged, and pointers y and z have moved up one level in the tree, but heap order is still violated After another exchange and moving pointers y and z up one more level, the while loop terminates.

Deleting a key Binomial-Heap-Delete(H,x) Running Time is Binomial-Heap-Decrease-Key(H,x,-∞) Binomial-Heap-Extract-Min(H) Running Time is Binomial-Heap-Decrease-Key : Binomial-Heap-Extract-Min :