A Simple Algorithm for Stable Minimum Storage Merging Pok-Son Kim Kookmin University, Department of Mathematics, Seoul , Korea Arne Kutzner Seokyeong University, Department of E-Business, Seoul , Korea
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 2 Merging Make one sorted array out of two consecutive sorted arrays , 491, 92
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
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.
We present..... …a simple, asymptotically optimal (regarding comparisons), stable, minimum storage merging algorithm called SPLITMERGE
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
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
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
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 !!!!
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
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
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 12 Splitting Example ? ? ?
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
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
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
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 16 Algorithm in Pseudo code
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
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
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/ recursion depth
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 n10n i k recursion level
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
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
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
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:
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
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
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 ?
SOFSEM 2007 A Simple Algorithm for Stable Minimum Storage Merging 28 Thank you very much for your attention