O(nm)是lower bound了吧? 请问一下O(nm)算法的思路是什么? 我能想到的是,假设矩阵大小是n*m,那么取m、n中较小的那个(假设是m)做m way merge,时间复杂度是O(mn log m)
【在 b*****t 的大作中提到】 : 俺只知道一个O(nm)的算法。
l*8
5 楼
I don't think O(nm) is possible. O(nm log(min(n,m)) is probably the best you can do. Consider the special case of a square nxn matrix, where elements along the diagonal line A[0][k],A[1][k-1],A[2][k-2]...,A[k][0] have very small differences in their values, yet are randomly ordered. By solving the 2D sorting problem, you've effectively sorted every such diagnoal line.
i agree. i don't think O(nm) is possible. this problem is similar to the rank/selection problem for a 2-D matrix.
you
【在 l***8 的大作中提到】 : I don't think O(nm) is possible. O(nm log(min(n,m)) is probably the best you : can do. : Consider the special case of a square nxn matrix, where elements along the : diagonal line A[0][k],A[1][k-1],A[2][k-2]...,A[k][0] have very small : differences in their values, yet are randomly ordered. By solving the 2D : sorting problem, you've effectively sorted every such diagnoal line.