Sorting and then sorting again...

You have the numbers 1 through 9 randomly placed in a 3 × 3 3 \times 3 grid.

First you sort each element of each column. Then you sort each element of each row.

In the end, is each element of each column necessarily sorted?

No Yes

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Ivo Zerkov
Sep 21, 2018

As it turns out, first sorting each column and then sorting each row of a matrix always preserves the sorting by columns. (That is, the 3x3 restraint in the original problem is unnecessary). This can be shown to be true in the following way:

Consider a matrix which has all its columns sorted. Assume that, when starting from the top of the matrix and sorting each successive row, at some point we reach an element which is smaller than the one above it, thus disproving the fact that the columns remain sorted. Now consider the two rows in which the discrepancy occurs. Let their elements respectively be a k a_k and b k b_k for k [ 1 , n ] k\in[1,n] . Since the columns were initially sorted, a k < b k a_k< b_k . Let’s now begin sorting the two rows anew. Let b i b_i and a j a_j be the smallest elements in their respective rows. If i = j i=j , then those two elements will go to the beginning of the sorted rows and will cause no discrepancy. We can then consider the remainder of the rows over and over until we reach a time where i j i\not=j . Since b i > a i > a j b_i>a_i>a_j , those two elements going to the beginning of the sorted rows will cause no issue. On the other hand, b j > b i > a i b_j>b_i>a_i , so we can move b j b_j below a i a_i without messing up the column-sort and repeat the argument again until the two rows are sorted. Since both cases preserve the column-sort, our assumption is wrong and the column-sort is always preserved.

Note that this solution assumed the worst-case scenario of having no two elements be equal. This is a worst-case scenario because two elements being equal poses no danger to the column-sort, so in a sense those two elements are given to us “for free”.

Dieter Schneider
Nov 24, 2018

Ervyn Manuyag
Sep 21, 2018

sort it by a magic square

Hmmm... Can you elaborate?

Geoff Pilling - 2 years, 8 months ago

Huh? Can you make this more specific?

Z G - 2 years, 8 months ago
Asif Mujawar
Sep 21, 2018

If we put in 3 by 3 magic square

Can you explain a bit what you mean here?

Geoff Pilling - 2 years, 8 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...