1

Since the elements of the matrix are bounded then I thought to use a variation of counting sort and then the running time maybe could be O(n^2), assuming that the size of the matrix is n^2.

Assuming that the result should be a sorted one dimensional array of size n^2 .

Can I get a hint ?

Dam
  • 125
  • 7
  • 4
    What does "sort a matrix" mean? Can you give an example of an unsorted matrix and what the output of your algorithm would be? – Stef Nov 17 '20 at 00:27
  • Hi, you might want to check out https://stackoverflow.com/questions/15599610/the-time-complexity-of-counting-sort – IronMan Nov 17 '20 at 00:31
  • @Stef yea you right. I edited. Thanks – Dam Nov 17 '20 at 00:31
  • 1
    Okay. So what's the question? You want a hint? A hint about what? – Stef Nov 17 '20 at 00:33
  • look into [radix sort](https://en.wikipedia.org/wiki/Radix_sort) It has `O(n)` time complexity – bolov Nov 17 '20 at 00:37

1 Answers1

1

You already have the answer in your tags... Counting sort will beat anything else in such a small range as [0, 127].

orlp
  • 112,504
  • 36
  • 218
  • 315