Stupid Columnsort Tricks Geeta Chaudhry Tom Cormen Dartmouth College Department of Computer Science.

Slides:



Advertisements
Similar presentations
From Geometry to Architecture and Construction. Consider a vertical section of polyhedrons that correspond to columns having different shift states. Each.
Advertisements

Creating Tables The basics, nothing pretty, but it works.
Lecture 24 MAS 714 Hartmut Klauck
Lecture 19: Parallel Algorithms
Lecture 3: Parallel Algorithm Design
Stupid Columnsort Tricks Geeta Chaudhry Tom Cormen Dartmouth College Department of Computer Science.
The Efficiency of Algorithms
CSE621/JKim Lec4.1 9/20/99 CSE621 Parallel Algorithms Lecture 4 Matrix Operation September 20, 1999.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
1 Parallel Algorithms III Topics: graph and sort algorithms.
Mesh connected networks. Sorting algorithms Efficient Parallel Algorithms COMP308.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Fractions - a Quick Review
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Computer Algorithms Lecture 11 Sorting in Linear Time Ch. 8
A table is an arrangement of data (words and numbers) in rows and columns. Tables range in complexity from those with only two columns and a title to.
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
MATH 224 – Discrete Mathematics
Chapter 5 Creating Page Templates
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
RMIT University; Taylor's College1 Lecture 6  To apply the Principle of Mathematical Induction  To solve the Towers of Hanoi puzzle  To define a recurrence.
Actual Building the Pages Tables. Using Table Elements  To build effective page templates, you must be familiar with the HTML table elements and attributes.
Box Method for Factoring Factoring expressions in the form of.
Approximation and Hardness Results for Packing Cycles Mohammad R. Salavatipour Department of Computing Science University of Alberta Joint work with M.
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
SCIENTIFIC NOTATION What is it? And How it works?.
Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Lecture PowerPoint Slides Basic Practice of Statistics 7 th Edition.
NORMAL DISTRIBUTION Chapter 3. DENSITY CURVES Example: here is a histogram of vocabulary scores of 947 seventh graders. BPS - 5TH ED. CHAPTER 3 2 The.
Histograms Lecture 14 Sec Tue, Sep 26, 2006.
CALTECH CS137 Winter DeHon CS137: Electronic Design Automation Day 13: February 20, 2002 Routing 1.
Chapter 5 Creating Page Templates. Principles of Web Design 2nd Ed. Chapter 5 2 Principles of Web Design Chapter 5 Objectives Understand table basics.
The Slope of a Line. Finding Slope of a Line The method for finding the steepness of stairs suggests a way to find the steepness of a line. A line drawn.
Equivalent Fractions A fraction is a ratio that compares how much of something exists. They contain a numerator ( the top ) and a denominator ( the bottom.
Fundamentals of Informatics Lecture 13 Reduction Bas Luttik.
Algorithms for hard problems Parameterized complexity Bounded tree width approaches Juris Viksna, 2015.
Adding two numbers together which have the same absolute value but are opposite in sign results in a value of zero. This same principle can be applied.
Sorting & Lower Bounds Jeff Edmonds York University COSC 3101 Lecture 5.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
Box Method for Factoring Factoring expressions in the form of.
Copyright © Cengage Learning. All rights reserved. 7 Rational Functions.
MATH 224 – Discrete Mathematics
Greedy algorithms: CSC317
1.5 Matricies.
Box Method for Factoring
Box Method for Factoring
Mesh connected networks. Sorting algorithms
SORTING NETWORKS.
Communication Complexity as a Lower Bound for Learning in Games
Multiplying by powers of 10 Decimals
Tables:.
Introduction to Functions
Topic 3: Data Binary Arithmetic.
Lecture 22: Parallel Algorithms
CHAPTER 1: Picturing Distributions with Graphs
Lecture 3 Induction Algorithm design techniques: induction
Exponential Functions
Principles of Computing – UFCFA3-30-1
Linear Sorting Sorting in O(n) Jeff Chastine.
Fractions and Decimals
Lecture 6 Algorithm Analysis
Lecture 6 Algorithm Analysis
Standard Measurement When measuring, it is sometimes necessary to change from one unit into another. Unit refers to what you are measuring. FOR EXAMPLE…
Early Computation Methods
Early Computation Methods
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Computer and Robot Vision I
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Stupid Columnsort Tricks Geeta Chaudhry Tom Cormen Dartmouth College Department of Computer Science

Columnsort  Sorts N numbers  Organized as r  s mesh  Divisibility restriction: s must divide r  Height restriction: r ≥ 2s 2  8 steps 1.Sort each column 2.Transpose 3.Sort each column 4.Untranspose 5.Sort each column 6.Shift down 1/2 column 7.Sort each column 8.Shift up 1/2 column

Proof of Correctness  Columnsort is oblivious  Use 0-1 Principle: If an oblivious algorithm sorts all input sets consisting solely of 0s and 1s, then it sorts all input sets with arbitrary values.  After step 3, the mesh consists of  Clean rows of 0s at the top  Clean rows of 1s at the bottom  ≤ s dirty rows between the clean rows

Proof of Correctness (continued)  After step 4, the mesh consists of  Clean columns of 0s on the left  Clean columns of 1s on the right  A dirty area of size ≤ s 2 between the clean columns  r ≥ 2s 2 ==> s 2 ≤ r/2 ==> the dirty area is at most 1/2 a column large

Proof of Correctness (continued)  If, entering step 5, the dirty area is at most 1/2 a column large, then steps 5–8 complete the sorting  If the dirty area fits in a single column, step 5 cleans it, and steps 6–8 leave the mesh clean  If the dirty area spans two columns, then it’s in the bottom half of one column and the top half of the next column.  Step 5 does not change this  Step 6 gets the dirty area into one column  Step 7 cleans it  Step 8 moves all values back to where they belong

Removing the Divisibility Restriction  Step 1: Sort each column  Each column has ≤ 1 0  1 transition  ≤ s 0  1 transitions  There may be a 1  0 transition going from one column to the next  ≤ s–1 1  0 transitions  Step 2: Transpose  Within rows, ≤ s 0  1 transitions, ≤ s–1 1  0 transitions

Divisibility Restriction (continued)  After step 2, let  X = dirty rows with one 0  1 transition, no 1  0  Y = dirty rows with one 1  0 transition, no 0  1  Z = all other dirty rows (≥ 1 0  1 and ≥ 1 1  0)  Number of dirty rows = |X| + |Y| + |Z|  All other rows are clean  Claim: max(|X|, |Y|) + |Z| ≤ s  Every row of X, Z contains ≥ 1 0  1 => |X| + |Z| ≤ s  Every row of Y, Z contains ≥ 1 1  0 => |Y| + |Z| ≤ s–1  max(|X|, |Y|) = |X| => max(|X|, |Y|) + |Z| ≤ s  max(|X|, |Y|) = |Y| => max(|X|, |Y|) + |Z| ≤ s–1  In either case, max(|X|, |Y|) + |Z| ≤ s

Divisibility Restriction (continued)  After step 3  Clean rows of 0s move to the top  Clean rows of 1s move to the bottom  Pair up the min(|X|, |Y|) pairs of rows with one row in X and other row in Y more 0s than 1s more 1s than 0s equal 0s and 1s from X: from Y:

Divisibility Restriction (continued)  In all cases, ≥ 1 clean row is formed  ≥ min(|X|, |Y|) new clean rows are created  Dirty rows remaining ≤ |X| + |Y| + |Z| – min(|X|, |Y|)  |X| + |Y| – min(|X|, |Y|) = max(|X|, |Y|) ==> Dirty rows remaining ≤ max(|X|, |Y|) + |Z| ≤ s  From here, it’s the same as the original proof  Dirty area size ≤ s 2 ≤ r/2 (half a column) after step 4  Steps 5–8 clean up the dirty area

Subblock Distribution  Divide up the mesh into s 1/2  s 1/2 subblocks  Each subblock contains s values  Add two steps between steps 3 and 4  Step 3.1: Perform any fixed permutation that moves all values in each subblock into all s columns  Step 3.2: Sort each column  The resulting algorithm is subblock columnsort  Works with relaxed height restriction of r ≥ 4s 3/2 (assuming the divisibility restriction)

Subblock Columnsort Correctness  After step 3, the line dividing 0s and 1s goes left to right and bottom to top (southwest to northeast)  Never turns back to the left  Never turns back toward the bottom  To show, suffices to show that after step 2, # of 0s in each column ≥ # of 0s in column to its right  How could a column have # of 0s < # of 0s in column to its right?  There would have to be a 1  0 transition in a row  But divisibility restriction => there are no 1  0 transitions in rows after step 2

Subblock Columnsort Correctness (continued)  After step 3.1, the number of 0s in any two columns differs by ≤ 2s 1/2  The dirty area is confined to an area s rows high and s columns wide  In subblocks, s 1/2  s 1/2  Dividing line passes through ≤ s 1/2 + 1 subblocks vertically and ≤ s 1/2 subblocks horizontally ==> ≤ 2s 1/2 subblocks total  Don’t double-count the 1 extra subblock  Step 3.1 distributes each subblock to all s columns  All clean subblocks distribute their 0s and 1s uniformly to each column  Number of 0s between any two columns differs by ≤ number of dirty subblocks = 2s 1/2

Subblock Columnsort Correctness (continued)  After step 4, the mesh consists of  Clean columns of 0s on the left  Clean columns of 1s on the right  A dirty area of size ≤ 2s 3/2 between the clean columns  After sorting in step 3.2, the dirty area is ≤ 2s 1/2 rows high and ≤ s columns wide  Size of dirty area is ≤ 2s 3/2

Subblock Columnsort Correctness (continued)  Finish up by observing that r ≥ 4s 3/2 is equivalent to 2s 3/2 ≤ r/2  Now the dirty area is at most 1/2 a column  Steps 5–8 clean up the dirty area  Can remove the divisibility restriction at the cost of tightening the height restriction to r ≥ 6s 3/2

Slabpose Columnsort  Another variation on columnsort  Loosens height restriction to r ≥ 4s 3/2  Has 10 steps  Partitions the mesh into vertical slabs

Conclusion  Removed and relaxed restrictions on columnsort  Divisibility restriction: s divides r  Height restriction: r ≥ 2s 2  Divisibility restriction is not necessary  Subblock columnsort  With divisibility restriction: r ≥ 4s 3/2  Without divisibility restriction: r ≥ 6s 3/2  Slabpose columnsort: r ≥ 4s 3/2