0

Given a matrix with m rows and n columns, where each entry consists of a pair (a,b) of integers. No pair appears twice in the matrix.

We would now like to order these pairs, such that for two pairs (a,b) and (c,d) which are in the same row, we have that the pair (a,b) is on the left of (c,d) if and only if ((a < c) or (a=c and b < d)), i.e. if the pair is lexicographically ordered according to its entries. Furthermore, for two pairs (a,b) and (c,d) in the same column, we have that (a,b) is below (c,d) if and only if ((b < d) or (b=d and a < c).

If we find a placement such that all rows and columns satisfy the above condition, we call it stable.

It is easy to obtain a stable placement by first sorting all pairs according to the row-condition, which takes O(mn log(mn)) time. Then split this list into m parts p_1,...,p_m (each consists now of n elements and for each (a,b) in p_i, (c,d) in p_j it is (a,b) < (c,d) if i < j). Now sort each part p_i according to the column-condition, which takes O(n log(n)) per part, i.e. O(mn log(n)) for all parts. Writing the sorted part p_i into column i gives a stable placement.

Now consider the special case m=n, N=n². With the above argument we get that a stable placement can be obtained in time O(N log(N)), which gives an upper bound. Now this poses the question:

What is a lower bound for this problem? Is O(N log(N)) optimal?

Skrodde
  • 655
  • 3
  • 7
  • 19
  • You might be interested in a paper by Anna Lubiw on "Doubly Lexical Orderings of Matrices" (http://epubs.siam.org/doi/abs/10.1137/0216057). She addresses what seems to be a similar problem but with real-valued entries. Her analysis was that the computation was O(K * log^2(K)) where K = m + n + e and where e = number of entries that are not equal to the smallest value. You might also want to check your analysis against hers. – Bill Province Oct 13 '15 at 14:59
  • Thank you for the reference. Sadly, the presented technique only seems to work with a doubly lexical ordering, i.e. an ordering where each matrix entry M_ii is just one (real) number and both rows and vectors are lexicographically increasing. I briefly thought about concatinating my two numbers to obtain a real number, but that does not work in the desired way. So it seems to me that the problem from the reference is a different problem after all. – Skrodde Oct 14 '15 at 08:18
  • Obviously, I meant to say "rows and columns as vectors". In particular, consider the matrix [[1,2,3],[2,0,1],[3,4,0]] which is doubly lexically ordered, but not anywhere near the order where I want to have it. This is since I consider the individual entries and in Lubiw's paper, the whole row- and column vectors are considered. – Skrodde Oct 14 '15 at 08:42
  • Is the matrix structure important? It seems to me that you could simply flatten the matrix to a list, sort the list, and reshape the result again to get a matrix. – Martin Thoma Oct 14 '15 at 08:54
  • When you only know the `<=` relationship of elements, but don't have more structure, `O(N log(N))` for sorting `N` elements is always a lower boundary. If you can actually reach this boundary depends if you have more constraints for sorting. – Martin Thoma Oct 14 '15 at 08:56
  • Hi moose, the matrix structure is indeed not important, is has to be a square matrix, however. Your upper comment exactly describes my procedure of establishing an `O(N log(N))` upper bound. Now I am asking for a lower bound. Note that there is not only one ordering `<=`, but two: one for the columns respecting the second value of the pair and then the first and another for the rows, respecting the first value and then the second. If both orderings where equal, then the reference from Bill would apply. However, they are not and therefore it is not that easy to establish a lower bound. – Skrodde Oct 15 '15 at 16:30

0 Answers0