Download presentation
Presentation is loading. Please wait.
Published byDale Griffith Modified over 9 years ago
1
A Simple Algorithm for Stable Minimum Storage Merging Pok-Son Kim Kookmin University, Department of Mathematics, Seoul 135-702, Korea Arne Kutzner Seokyeong University, Department of E-Business, Seoul 136-704, Korea
2
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 2 Merging Make one sorted array out of two consecutive sorted arrays 491392 3, 491, 92
3
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 3 Lower Bounds for Merging Number of comparisons –Argumentation over the decision tree (see Knuth) Number of assignments –Each element can change its position in the final sequence for
4
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 4 Notions An algorithm merges two adjacent sequences with “minimum storage” when it needs bits additional space at most. Stability: Merging algorithm preserves the initial ordering of elements with equal value.
5
We present..... …a simple, asymptotically optimal (regarding comparisons), stable, minimum storage merging algorithm called SPLITMERGE
6
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 6 SPLITMERGE: Step 1 - Splitting We compute boundaries in our inputs u and v so that we get the following property: u1u1 u2u2 v1v1 v2v2
7
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 7 SPLITMERGE: Step 2 – Rotation We rotate u 2 v 1 to v 1 u 2 u1u1 u2u2 v1v1 v2v2 u1u1 u2u2 v1v1 v2v2
8
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 8 SPLITMERGE: Step 3 – Recursive Application We have: 1. u 1 u 2 and u 1 v 2 2. v 1 u 2 and v 1 v 2 u1u1 u2u2 v1v1 v2v2 left recursionright recursion
9
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 9 Stability Lemma: SPLITMERGE is stable. Proof: u1u1 u2u2 v1v1 v2v2 u1u1 u2u2 v1v1 v2v2 > rotation !!!!
10
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 10 How do we split? Repeated halving of two search spaces until these are reduced to single points (the borders of a rotation). For asymmetric inputs one element of the smaller side “freezes” after some time
11
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 11 Symmetric Splitting – Graphical Description u 21 xu 22 v 21 yv 22 search spaces x y u 22 v 21 xy u 21 v 22 xy x y
12
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 12 Splitting Example 98651655201880 98651655201880 98651655201880 98651655201880 ? ? ?
13
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 13 Symmetric Splitting – Asymmetric Inputs (1) x u1u1 u3u3 v1v1 v 21 yv 22 v3v3 single search space After some time one element “freezes” (here x) x can “belong” to u 1, u 3 or both x belongs to u 1 means u 1 x v 3 x belongs to u 3 means xu 3 v 1
14
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 14 Symmetric Splitting – Asymmetric Inputs (2) x u1u1 u3u3 v1v1 v3v3 Rotation – we distinguish two different cases if x belongs to u 3 : x u1u1 u3u3 v1v1 v3v3 otherwise : x u1u1 u3u3 v1v1 v3v3
15
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 15 Symmetric Splitting – Asymmetric Inputs (3) Recursion – we distinguish several cases if x belongs to u 1 x u1u1 u3u3 v1v1 v3v3 otherwise x u1u1 u3u3 v1v1 v3v3 left Recursionright Recursion
16
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 16 Algorithm in Pseudo code
17
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 17 Some Remarks … The “belongs to” information can be followed from the variables l, r and m
18
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 18 Worst Case Complexity Lemma: The recursion depth is limited by min, where Corollary: Minimum Storage Algorithm
19
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 19 Worst Case Complexity (Comparisons) Special case m→ m/2 (1) m10m10 n32n32 m12m12 m22m22 m32m32 m42m42 m11m11 m21m21 n42n42 n22n22 n12n12 n11n11 n21n21 n10n10 m m/2 m/4 1111 recursion depth
20
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 20 Worst Case Complexity (Comparisons) Special case m→ m/2 (2) m10m10 n32n32 m12m12 m22m22 m32m32 m42m42 m11m11 m21m21 n42n42 n22n22 n12n12 n11n11 n21n21 n10n10 0 1 2 i k recursion level
21
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 21 Worst Case Complexity (Comparisons) Special case m→ m/2 (3) Overall number of comparisons: Mathematical Machinery
22
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 22 Worst Case Complexity How to treat the other cases? (1) Example: Maximum spanning case
23
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 23 Worst Case Complexity How to treat other cases? (2) Trick: Mapping into a corresponding “ m → m/2 case” by the introduction of recursion groups –A recursion group consists of one or several recursion levels –Grouping of recursion levels into recursion groups so that each recursion group holds at most 2 i-1 recursion levels. –Altogether k+1 recursion groups
24
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 24 Worst Case Complexity How to treat other cases? (3) Mapping for the maximum spanning case:
25
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 25 Assignments / Worst Case Complexity Theorem: The S PLITMERGE algorithm needs assignments. Sketch of Proof: At most k+1 recursion groups with O(m+n) many assignments for every group
26
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 26 Benchmarks n,m : lengths of input sequences (m=n) i : number of different input elements t e : execution time in ms #comp : number of comparisons
27
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 27 Summary Simply structured algorithm using a novel binary partition technique Doesn’t rely on any third algorithm as subpart Short definition in Pseudo Code Asymptotically optimal regarding the number of comparisons Nice Textbook algorithm ?
28
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 28 Thank you very much for your attention
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.