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

comparison based merging upper and lower bounds
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Comparison Based Merging Upper and Lower bounds

EMADS Fall 2003: Comparison Based Merging Page 1

slide-2
SLIDE 2

Merging

Input: Two sorted lists X and Y of length n and m. We may assume n ≥ m. X: Y : n 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

slide-3
SLIDE 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

slide-4
SLIDE 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)) = Θ(nlog log n log n ) = o(n)

EMADS Fall 2003: Comparison Based Merging Page 4

slide-5
SLIDE 5

Graphically

100 200 300 400 500 600 700 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

slide-6
SLIDE 6

Better Upper Bound

X: Y : n m n/m x1 x2 · · · xi · · · xm y1 · · · yj · · · ym

(Assume ascending order) if xi < yj i++ else binary search from xi−1 to xi j++

Number of comparisons: m + m log(n/m)

EMADS Fall 2003: Comparison Based Merging Page 6

slide-7
SLIDE 7

Lower Bound

There are n+m

m

  • different possible results of the merging two sorted lists
  • f lengths n and m.

+ → So any decision tree for merging must have at least that many leaves. It must hence have height at least log( n + m m

  • )

EMADS Fall 2003: Comparison Based Merging Page 7

slide-8
SLIDE 8

Lemmas

For n ≥ m: 1) n + m m

  • = (n + m)(n + m − 1) · · · (n + 1)

m(m − 1) · · · 1 ≥ (n/m)m 2) n + m m

2m m

  • ≥ 2m(2m − 1) · · · (m + 1)

m(m − 1) · · · 1 ≥ 2(m m)2(m − 1/2 m − 1 )2(m − 2/2 m − 2 )2(m − 3/2 m − 3 ) · · · ≥ 2m

EMADS Fall 2003: Comparison Based Merging Page 8

slide-9
SLIDE 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

slide-10
SLIDE 10

Lower Bound Computation

log( n + m m

  • )

≥ max{log(2m), log((n/m)m)} = max{m, m log(n/m)} = Ω(m + m log(n/m)})

EMADS Fall 2003: Comparison Based Merging Page 10