How to sort a m x n matrix which has all its m rows sorted and n columns sorted?

后端 未结 3 2030
刺人心
刺人心 2020-12-14 09:20

Given a matrix with m rows and n columns, each of which are sorted. How to efficiently sort the entire matrix?

I know a solution which runs in O(m n log(min(m,n)). I

3条回答
  •  暖寄归人
    2020-12-14 10:21

    If elements are integers within a certain range k where K=o(mn), we can use count sort with extra space to achieve O(mn), otherwise the mnlog(min(m,n)) is the best we can do.

提交回复
热议问题