comparison based merging upper and lower bounds
play

Comparison Based Merging Upper and Lower bounds EMADS Fall 2003: - PowerPoint PPT Presentation

Comparison Based Merging Upper and Lower bounds EMADS Fall 2003: Comparison Based Merging Page 1 Merging Input: Two sorted lists X and Y of length n and m . We may assume n m . n X : Y : m Theorem: In a comparison based model, the


  1. Comparison Based Merging Upper and Lower bounds EMADS Fall 2003: Comparison Based Merging Page 1

  2. Merging Input: Two sorted lists X and Y of length n and m . We may assume n ≥ m . n X : Y : m Theorem: In a comparison based model, the complexity of merging X and Y is Θ( m (log( n/m ) + 1)) EMADS Fall 2003: Comparison Based Merging Page 2

  3. Simple Upper Bounds Standard Merge: Θ( n + m ) Binary Insertion of Y in X : Θ( m log n )) For ”large” m ( m = Θ( n ) ): Θ( n + m ) = Θ( m (log( n/m ) + 1)) For ”small” m (e.g. m = O ( √ n ) ): Θ( m log n ) = Θ( m (log( n/m ) + 1)) EMADS Fall 2003: Comparison Based Merging Page 3

  4. The Simple Bounds are Sub-Optimal E.g. for m = Θ( n/ log n ) : Θ( n + m ) = Θ( n ) Θ( m log n ) = Θ( n ) Θ( m (log( n/m ) + 1)) = Θ( n log log n ) = o ( n ) log n EMADS Fall 2003: Comparison Based Merging Page 4

  5. Graphically 700 600 500 400 300 200 100 20 40 60 80 100 n + m m log n m (log( n/m ) + 1) n + m = 200 EMADS Fall 2003: Comparison Based Merging Page 5

  6. Better Upper Bound n/m n X : x 1 x 2 x i x m · · · · · · y 1 · · · y j · · · y m Y : (Assume ascending order) m Number of if x i < y j i ++ comparisons: else binary search from x i − 1 to x i m + m log( n/m ) j ++ EMADS Fall 2003: Comparison Based Merging Page 6

  7. Lower Bound � n + m � There are different possible results of the merging two sorted lists m of lengths n and m . → + So any decision tree for merging must have at least that many leaves. It must hence have height at least � n + m � log( ) m EMADS Fall 2003: Comparison Based Merging Page 7

  8. Lemmas For n ≥ m : 1) � n + m � = ( n + m )( n + m − 1) · · · ( n + 1) ≥ ( n/m ) m m ( m − 1) · · · 1 m 2) � n + m � � 2 m � ≥ 2 m (2 m − 1) · · · ( m + 1) ≥ m ( m − 1) · · · 1 m m m )2( m − 1 / 2 m − 1 )2( m − 2 / 2 m − 2 )2( m − 3 / 2 ≥ 2( m m − 3 ) · · · ≥ 2 m EMADS Fall 2003: Comparison Based Merging Page 8

  9. Lemmas 3) h ( n ) ≥ f ( n ) and h ( n ) ≥ g ( n ) � h ( n ) ≥ max { f ( n ) , g ( n ) } 4) For f and g positive: max { f ( n ) , g ( n ) } = Θ( f ( n ) + g ( n )) EMADS Fall 2003: Comparison Based Merging Page 9

  10. Lower Bound Computation � n + m � log( ) m ≥ max { log(2 m ) , log(( n/m ) m ) } = max { m, m log( n/m ) } = Ω( m + m log( n/m ) } ) EMADS Fall 2003: Comparison Based Merging Page 10

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend