Binomial queues l.jpg
This presentation is the property of its rightful owner.
Sponsored Links
1 / 26

Binomial Queues PowerPoint PPT Presentation


  • 452 Views
  • Updated On :
  • Presentation posted in: General

Binomial Queues. Text Read Weiss, § 6.8 Binomial Queue Definition of binomial queue Definition of binary addition Building a Binomial Queue Sequence of inserts What in the world does binary addition have in common with binomial queues?. Motivation.

Download Presentation

Binomial Queues

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Binomial queues l.jpg

Binomial Queues

  • Text

  • Read Weiss, §6.8

  • Binomial Queue

  • Definition of binomial queue

  • Definition of binary addition

  • Building a Binomial Queue

  • Sequence of inserts

  • What in the world does binary addition have in common with binomial queues?


Motivation l.jpg

Motivation

  • A binary heap provides O(log n) inserts and O(log n) deletes but suffers from O(n log n) merges

  • A binomial queue offers O(log n) inserts and O(log n) deletes and O(log n) merges

  • Note, however, binomial queue inserts and deletes are more expensive than binary heap inserts and deletes


Slide3 l.jpg

Definition

A Binomial Queue is a collection of heap-ordered trees known as a forest. Each tree is a binomial tree. A recursive definition is:

  • A binomial tree of height 0 is a one-node tree.

  • A binomial tree, Bk, of height k is formed by attaching a binomial tree Bk−1 to the root of another binomial tree Bk−1 .


Examples l.jpg

Examples

B2

B0

4

B1

4

4

5

8

8

4

12

7

B3

5

8

10

8

12

11

4

6

7

B4

5

8

10

7

8

15

9

10

12

11

10

24

22


Questions l.jpg

Questions

  • How many nodes does the binomial tree Bkhave?

  • How many children does the root of Bkhave?

  • What types of binomial trees are the children of the root of Bk?

  • Is there a binomial queue with one node? With two nodes? With three nodes? … With n nodes for any positive integer n?


Binary numbers l.jpg

Binary Numbers

  • Consider binary numbers

  • Positional notation:

    • 2524 23 22 21 20

    • 0 1 0 1 1 0

    • 0 + 16 + 0 + 4 + 2 + 0 = 22

       0101102 = 2210

  • What is the decimal value of these binary numbers?

    • 011=

    • 101=

    • 10110=

    • 1001011=


  • Slide7 l.jpg

    Binary Numbers

    • Consider binary numbers

    • Positional notation:

      • 2524 23 22 21 20

      • 0 1 0 1 1 0

      • 0 + 16 + 0 + 4 + 2 + 0 = 22

         0101102 = 2210

  • What is the decimal value of these binary numbers?

    • 011= 3

    • 101= 5

    • 10110= 22

    • 1001011 = 75


  • Binary addition l.jpg

    Binary Addition

    (carry)11

    1 0 1 1 0 1 0

    + 0 0 1 1 1 0 0

    -----------------

    1 1 1 0 1 1 0


    Slide9 l.jpg

    Merging Binomial Queues

    Consider two binomial queues, H1 and H2

    3

    4

    6

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    12

    3

    1

    H2

    21

    16

    6

    23


    Slide10 l.jpg

    Merging Binomial Queues

    Merge two B0 trees forming new B1 tree

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    6

    12

    3

    H2

    21

    16

    6

    23


    Slide11 l.jpg

    Merging Binomial Queues

    Merge two B1 trees forming new B2 tree

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    12

    6

    16

    3

    H2

    21

    6

    23


    Slide12 l.jpg

    Merging Binomial Queues

    Merge two B2 trees forming new B3 tree (but which two B2 trees?)

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    12

    6

    16

    3

    H2

    21

    6

    23


    Slide13 l.jpg

    Merging Binomial Queues

    Which two B2 trees? Arbitrary decision: merge two original B2 trees

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    12

    6

    16

    3

    H2

    21

    6

    23


    Slide14 l.jpg

    Merging Binomial Queues

    Which two B2 trees? Arbitrary decision: merge two original B2 trees

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    12

    6

    16

    3

    H2

    21

    6

    23


    Slide15 l.jpg

    Merging Binomial Queues

    Which root becomes root of merged tree? Arbitrary decision: in case of a tie, make the root of H1 be the root of the merged tree.

    3

    4

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    1

    12

    6

    16

    3

    H2

    21

    6

    23


    Slide16 l.jpg

    Merging Binomial Queues

    Merge two B2 trees forming new B3 tree

    4

    H1

    7

    5

    8

    10

    8

    12

    11

    1

    12

    6

    3

    16

    3

    15

    H2

    5

    21

    6

    27

    23


    Slide17 l.jpg

    Merging Binomial Queues

    Merge two B3 trees forming a new B4 tree

    H1

    3

    3

    4

    15

    5

    21

    7

    6

    5

    8

    10

    27

    23

    8

    1

    12

    11

    12

    6

    16

    H2


    Slide18 l.jpg

    Merging Binomial Queues

    Call new binomial queue H3

    3

    H3

    3

    4

    1

    15

    5

    21

    12

    7

    6

    6

    5

    8

    10

    27

    23

    16

    8

    12

    11


    Slide19 l.jpg

    Merging Binomial Queues

    Reconsider the two original binomial queues, H1 and H2 and identify types of trees

    3

    4

    6

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    12

    11

    B0

    B3

    B2

    2

    3

    1

    H2

    21

    16

    6

    23

    B0

    B2

    B1


    Slide20 l.jpg

    Merging Binomial Queues

    Represent each binomial queue by a binary number

    3

    4

    6

    H1

    15

    7

    5

    5

    8

    10

    27

    8

    B4 B3 B2 B1 B0

    0 1 1 0 1

    12

    11

    B0

    B3

    B2

    2

    3

    1

    H2

    21

    16

    6

    23

    B4 B3 B2 B1 B0

    0 0 1 1 1

    B0

    B2

    B1


    Slide21 l.jpg

    Merging Binomial Queues

    Note that the merged binomial queue can be represented by the binary sum

    3

    4

    6

    H1

    15

    7

    5

    5

    B4 B3 B2 B1 B0

    0 1 1 0 1

    8

    10

    27

    8

    12

    11

    2

    3

    1

    H2

    21

    16

    6

    B4 B3 B2 B1 B0

    0 0 1 1 1

    23

    3

    H3

    3

    4

    1

    15

    5

    21

    2

    7

    B4 B3 B2 B1 B0

    1 0 1 0 0

    6

    6

    5

    8

    10

    27

    23

    16

    8

    12

    11


    Slide22 l.jpg

    This suggests a way to implement binomial queues


    Implementing binomial queues l.jpg

    Implementing Binomial Queues

    • Use a k-ary tree to represent each binomial tree

    • Use a Vector to hold references to the root node of each binomial tree


    Slide24 l.jpg

    Implementing Binomial Queues

    Use a k-ary tree to represent each binomial tree. Use an array to hold references to root nodes of each binomial tree.

    3

    4

    6

    H1

    15

    7

    5

    5

    B4 B3 B2 B1 B0

    0 1 1 0 1

    8

    10

    27

    8

    12

    11

    H1

    B4 B3 B2 B1 B0

    ØØ

    4

    8

    5

    3

    12

    7

    6

    5

    8

    15

    10

    27

    11


    Questions25 l.jpg

    Questions

    • We now know how to merge two binomial queues. How do you perform an insert?

    • How do you perform a delete?

    • What is the order of complexity of a merge? an insert? a delete?


    Implementing binomial queues26 l.jpg

    Implementing Binomial Queues

    Carefully study Java code in

    Weiss, Figure 6.52 – 6.56


  • Login