Stupid Columnsort Tricks - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Stupid Columnsort Tricks

Description:

Stupid Columnsort Tricks Geeta Chaudhry Tom Cormen Dartmouth College Department of Computer Science Columnsort Sorts N numbers Organized as r s mesh Divisibility ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 17
Provided by: ThomasC172
Category:

less

Transcript and Presenter's Notes

Title: Stupid Columnsort Tricks


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

2
Columnsort
  • Sorts N numbers
  • Organized as r s mesh
  • Divisibility restriction s must divide r
  • Height restriction r 2s2
  • 8 steps
  • Sort each column
  • Transpose
  • Sort each column
  • Untranspose
  • Sort each column
  • Shift down 1/2 column
  • Sort each column
  • Shift up 1/2 column

3
Proof of Correctness
  • Columnsort is oblivious
  • Use 0-1 PrincipleIf 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

4
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 s2 between the clean
    columns
  • r 2s2 gt s2 r/2 gt the dirty area is at
    most 1/2 a column large

5
Proof of Correctness (continued)
  • If, entering step 5, the dirty area is at most
    1/2 a column large, then steps 58 complete the
    sorting
  • If the dirty area fits in a single column, step 5
    cleans it, and steps 68 leave the mesh clean
  • If the dirty area spans two columns, then its 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

6
Removing the Divisibility Restriction
  • Step 1 Sort each column
  • Each column has 1 0-gt1 transition
  • s 0-gt1 transitions
  • There may be a 1-gt0 transition going from one
    column to the next
  • s1 1-gt0 transitions
  • Step 2 Transpose
  • Within rows, s 0-gt1 transitions, s1 1-gt0
    transitions

7
Divisibility Restriction (continued)
  • After step 2, let
  • X dirty rows with one 0-gt1 transition, no 1-gt0
  • Y dirty rows with one 1-gt0 transition, no 0-gt1
  • Z all other dirty rows ( 1 0-gt1 and 1 1-gt0)
  • 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-gt1 gt X Z
    s
  • Every row of Y, Z contains 1 1-gt0 gt Y Z
    s1
  • max(X, Y) X gt max(X, Y) Z s
  • max(X, Y) Y gt max(X, Y) Z s1
  • In either case, max(X, Y) Z s

8
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 000000001111 111110000000
000000000000 111110001111
more 1s than 0s 000111111111 111111110000
000111110000 111111111111
equal 0s and 1s 000011111111 111100000000
000000000000 111111111111
from X
from Y
9
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)gt
    Dirty rows remaining max(X, Y) Z
    s
  • From here, its the same as the original proof
  • Dirty area size s2 r/2 (half a column) after
    step 4
  • Steps 58 clean up the dirty area

10
Subblock Distribution
  • Divide up the mesh into s1/2 s1/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
    4s3/2 (assuming the divisibility restriction)

11
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 lt of 0s in
    column to its right?
  • There would have to be a 1-gt0 transition in a row
  • But divisibility restriction gt there are no 1-gt0
    transitions in rows after step 2

12
Subblock Columnsort Correctness (continued)
  • After step 3.1, the number of 0s in any two
    columns differs by 2s1/2
  • The dirty area is confined to an area s rows high
    and s columns wide
  • In subblocks, s1/2 s1/2
  • Dividing line passes through s1/2 1 subblocks
    vertically and s1/2 subblocks horizontally gt
    2s1/2 subblocks total
  • Dont 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 2s1/2

13
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 2s3/2 between the clean
    columns
  • After sorting in step 3.2, the dirty area is
    2s1/2 rows high and s columns wide
  • Size of dirty area is 2s3/2

14
Subblock Columnsort Correctness (continued)
  • Finish up by observing that r 4s3/2 is
    equivalent to 2s3/2 r/2
  • Now the dirty area is at most 1/2 a column
  • Steps 58 clean up the dirty area
  • Can remove the divisibility restriction at the
    cost of tightening the height restriction to r
    6s3/2

15
Slabpose Columnsort
  • Another variation on columnsort
  • Loosens height restriction to r 4s3/2
  • Has 10 steps
  • Partitions the mesh into vertical slabs

16
Conclusion
  • Removed and relaxed restrictions on columnsort
  • Divisibility restriction s divides r
  • Height restriction r 2s2
  • Divisibility restriction is not necessary
  • Subblock columnsort
  • With divisibility restriction r 4s3/2
  • Without divisibility restriction r 6s3/2
  • Slabpose columnsort r 4s3/2
Write a Comment
User Comments (0)
About PowerShow.com