Skip to main content
Source Link

What is the fastest way to sort numbers lexicographically?

I have $N$ sequences of numbers. None of them is longer than $10^6$. I want to sort those sequences lexicographically. For example, given sequences {1, 2, 4}, {1, 2, 3}, {2, 5, 7}, {2}, I want to have them sorted in this way - {1, 2, 3}, {1, 2, 4}, {2}, {2, 5, 7}. What is the fastest way to do this? Using quicksort and just comparing them in a normal way I can get $O(N∗K∗logN)$ but this is very slow.