Reputation: 184
Suppose I have a file of many lines of string, how to rank the lines of string in lexicographic order?
Details:
What I can figure out is an external merge sort, is there any better idea for this specified problem?
Upvotes: 1
Views: 105
Reputation: 23049
The difference between file size and the memory is not that big, therefore I would suggest to split file into more smaller files based on first letter - or if it is not enough, by the first two letters.
Then you can sort each of them with quicksort and save it and when then they are sorted, you can put them back together.
It would be still O(N) I/O operations and O(n*log(N)) CPU operations.
PS : External merge sort is also good way.
Upvotes: 2