1 / 19

CSE 326: Data Structures Binomial Queues

Explore the structural properties and operations on binomial queues. Learn about merging, insertion, deletion, and complexity analysis. See examples of binomial queue merges and deletions with detailed explanations.

nelliec
Download Presentation

CSE 326: Data Structures 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 326: Data StructuresBinomial Queues Peter Henry on behalf of James Fogarty Autumn 2007

  2. Yet Another Data Structure:Binomial Queues • Structural property • Forest of binomial trees with at mostone tree of any height • Order property • Each binomial tree has the heap-order property What’s a forest? What’s a binomial tree?

  3. The Binomial Tree, Bh • Bh has height h and exactly 2h nodes • Bh is formed by making Bh-1 a child of another Bh-1 • Root has exactly h children • Number of nodes at depth d is binomial coeff. • Hence the name; we will not use this last property B0 B1 B2 B3

  4. Binomial Queue with n elements Binomial Q with n elements has a unique structural representation in terms of binomial trees! Write n in binary: n = 1101 (base 2) = 13 (base 10) 1 B3 1 B2 No B1 1 B0

  5. Properties of Binomial Queue • At most one binomial tree of any height • n nodes  binary representation is of size ?  deepest tree has height ?  number of trees is ? Define: height(forest F) = maxtree T in F { height(T) } Binomial Q with n nodes has height Θ(log n) O(log n)

  6. Operations on Binomial Queue • Will again define merge as the base operation • insert, deleteMin, buildBinomialQ will use merge • Can we do increaseKey efficiently?decreaseKey? • What about findMin? Yes! Just likeBinary Heaps log n normally O(1) if you maintain min explicitly over ops

  7. Merging Two Binomial Queues Essentially like adding two binary numbers! • Combine the two forests • For k from 0 to maxheight { • m total number of Bk’s in the two BQs • if m=0: continue; • if m=1: continue; • if m=2: combine the two Bk’s to form a Bk+1 • if m=3: retain one Bk and combine the other two to form a Bk+1 } # of 1’s 0+0 = 0 1+0 = 1 1+1 = 0+c 1+1+c = 1+c Claim: When this process ends, the forest has at most one tree of any height

  8. Example: Binomial Queue Merge H1: H2: -1 5 1 3 21 3 9 2 7 6 1 11 5 7 8 6

  9. Example: Binomial Queue Merge H1: H2: -1 5 1 3 3 9 2 7 6 1 21 11 5 7 8 6

  10. Example: Binomial Queue Merge H1: H2: -1 5 1 3 9 2 7 6 1 3 11 5 7 8 21 6

  11. Example: Binomial Queue Merge H1: H2: -1 1 3 5 2 7 1 3 11 9 5 6 8 21 6 7

  12. Example: Binomial Queue Merge H1: H2: -1 1 3 2 1 5 7 11 3 5 8 9 6 6 21 7

  13. Example: Binomial Queue Merge H1: H2: -1 1 3 2 1 5 7 11 3 5 8 9 6 6 21 7

  14. Complexity of Merge Constant time for each height Max number of heights is: log n  worst case running time = Θ( ) log n

  15. Insert in a Binomial Queue Create a single node BQ and merge into existing BQ (show by picture) Θ(log n) worst case Θ(1) on average: first 0 in binary repr 0/1 with prob 0.5 so expected time: 2 Insert(x): Similar to leftist or skew heap runtime Worst case complexity: same as mergeO( ) Average case complexity: O(1) Why?? Hint: Think of adding 1 to 1101

  16. deleteMin in Binomial Queue Similar to leftist and skew heaps…. • find Bi with smallest root • delete root of Bi gives new BinQ BQ’ • Merge BQ’ with (BQ -{Bi})

  17. deleteMin: Example BQ 7 3 4 8 5 7 find and deletesmallest root How long does FIND take? O(log N) merge BQ (withoutthe shaded part) and BQ’ 3 8 5 BQ’ Do merge on tabletbefore next slide 7

  18. deleteMin: Example Result: 7 4 8 5 7 runtime: Θ(log n)

More Related