문제

Say you are given a list of names, S = {s1, s2 ... sn} and you want to sort them lexicographically.

How would you guarantee that the running time of the sort is O(the total sum of the lengths of all the words)?

Any useful techniques?

도움이 되었습니까?

해결책

One simple solution would be to use MSD radix sort, assuming a constant-size alphabet. Replace "digit" by "character" while reading the algorithm description. You will also need to throw out strings that are smaller than i if you are currently processing the position i, otherwise you won't get the desired runtime.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top