Lecture Notes on Binomial Heaps | CS 245, Study notes of Data Structures and Algorithms

Material Type: Notes; Professor: Galles; Class: Data Struct & Algorithms; Subject: Computer Science; University: University of San Francisco (CA); Term: Intersession 2009;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-mzo
koofers-user-mzo 🇺🇸

5

(1)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS245-2009S-20 Binomial Heaps 1
20-0: Binomial Trees
B0is a tree containing a single node
To build Bk:
Start with Bk1
Add Bk1as left subtree
20-1: Binomial Trees
B0B1B2B3B4
20-2: Binomial Trees
B0B1B2B3B4
20-3: Binomial Trees
Equivalent defintion
B0is a binomial heap with a single node
Bkis a binomial heap with kchildren:
B0. . . Bk1
20-4: Binomial Trees
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lecture Notes on Binomial Heaps | CS 245 and more Study notes Data Structures and Algorithms in PDF only on Docsity!

20-0: Binomial Trees

  • B 0 is a tree containing a single node
  • To build Bk:
    • • Start withAdd B Bk− 1 k− 1 as left subtree 20-1: B 0 Binomial Trees B 1 B 2 B 3 B (^4)

20-2: B 0 Binomial Trees B 1 B 2 B 3 B (^4)

20-3: Binomial Trees

  • Equivalent defintion
    • • BB (^0) k is a binomial heap with a single nodeis a binomial heap with k children:
      • B 0... Bk− 1 20-4: Binomial Trees

B 0 B 1 B 2 B 3 B (^4)

20-5: B 0 Binomial Trees B 1 B 2 B 3 B (^4)

20-6: Binomial Trees

  • Properties of binomial trees Bk
    • • ContainsHas height 2 k k^ nodes
    • Contains^ (^ ki^ ) nodes at depth i for i = 0... k 20-7: Binomial Heaps
  • A Binomial Heap is:
  • Set of binomial trees, each of which has the heap property • Each node in every tree is <= all of its children
  • All trees in the set have a different root degree • Can’t have two B 3 ’s, for instance

20-8: Binomial Heaps

  • How long does it take? 20-12: Binomial Heaps
  • How can we find the minimum element in a binomial heap?
  • Look at the root of each tree in the list, find smallest value
  • How long does it take?
  • • Heap hasRepresent n n elements as a binary number
  • • BNumber of trees in heapk is in heap iff kth binary digit of ∈ O(lg n) n is 1

20-13: Binomial Heaps

  • Merging Heaps H 1 and H 2
    • • Merge root lists ofWhat property of binomial heaps may be broken? H 1 and H 2
    • How do we fix it? 20-14: Binomial Heaps
  • Merging Heaps H 1 and H 2
  • Merge root lists of • Could now have two trees with same degree H 1 and H 2
  • Go through list from smallest degree to largest degree • If two trees have same degree, combine them into one tree of larger degree
  • If three trees have same degree (how can this happen?) leave one, combine other two into tree oflarger degree 20-15: Binomial Heaps 10 5 22 7 25

20-16: Binomial Heaps

20-17: Binomial Heaps 10 5 22 7 25

12 13 15 17

8 9 15 20

11

3 14 6 30

20-18: Binomial Heaps 10 5 22 7 25

12 13 15 17

8 9 15 20

11

3 14 6 30

20-19: Binomial Heaps

20-23: Binomial Heaps

  • Removing minimum element 10 5 22 7 25

12 13 15 17

8 9 15 20

11

6 14 30

20-24: Binomial Heaps

  • Removing minimum element 10 5

22 7

25

12

13 15

17

8

9 15

20

11

6 14

30

20-25: Binomial Heaps

  • Removing minimum element 10 5

22 7

25

12

13 15

17

8

9 15

20

11

6

14

30

20-26: Binomial Heaps

  • Removing minimum element

10

5

22 7

25

12

13 15

17

8

9 15

11 20

6

14

30 20-27: Binomial Heaps

  • Removing minimum element
  • Exactly like standard, binary heaps
  • Time: O(lg n) 20-32: Binomial Heaps
  • How could we delete an arbitrary element (assuming we had a pointer to this element)?

Deletethis key

20-33: Binomial Heaps

  • How could we delete an arbitrary element (assuming we had a pointer to this element)?
    • • Decrease key toRemove smallest, Time −∞, Time O(lg O n(lg) n)