Docsity

Lecture Slides on Binomial Heaps - Data Structures and Algorithms | CS 112, Study notes of Computer Science

Partial preview of the text

Download Lecture Slides on Binomial Heaps - Data Structures and Algorithms | CS 112 and more Study notes Computer Science in PDF only on Docsity!

Data Structures and Algorithms

CS245-2008S-20Binomial Heaps

David Galles Department of Computer ScienceUniversity of San Francisco

Binomial Trees Bis a tree containing a single node^0 To build

B:k

Start with

Bk−

Add

Bk−

as left subtree 1

Binomial Trees

B^0

B^1

B^2

B^3

B^4

Binomial Trees Equivalent defintion^ B

is a binomial heap with a single node 0 Bis a binomial heap withk

k^ children:

B... B^0

k−^1

Binomial Trees

B^0

B^1

B^2

B^3

B^4

Binomial Trees Properties of binomial trees

Bk

Contains

k^2 nodes

Has height

k

Contains

(^ )k i

nodes at depth

i^ for

i^ = 0

... k

Binomial Heaps

Binomial Heaps Representing Binomial Heaps^ Each node contains:

left child, right sibling, parent pointers degreee (is the tree rooted at this node

B,^0

B, etc.)^1 data Each list of children sorted by degree

Binomial Heaps How can we find the minimum element in abinomial heap? How long does it take?

Binomial Heaps How can we find the minimum element in abinomial heap?^ Look at the root of each tree in the list, findsmallest value How long does it take?^ Heap has

n^ elements

Represent

n^ as a binary number

Bis in heap iffk^

kth binary digit of

n^ is 1

Number of trees in heap

∈^ O

(lg^ n

Binomial Heaps Merging Heaps

H^1

and

H^2

Merge root lists of

H^1

and

H^2

Could now have two trees with same degree Go through list from smallest degree to largestdegree If two trees have same degree, combinethem into one tree of larger degree If three trees have same degree (how canthis happen?) leave one, combine other twointo tree of larger degree

Binomial Heaps

Binomial Heaps

Binomial Heaps