algorithm - left to right radix sort -
radix sort sorts numbers starting lease significant digit significant digit. have following scenario :
my alphabet english alphabet , therefore "numbers" english language strings. characters of these strings revealed 1 @ time left right. is, significant digit , strings, revealed first , on. @ stage, have set of k character long strings, sorted. @ point 1 character more revealed every string. , want sort new set of strings. how do efficiently without starting scratch ?
for example if had following sorted set { for, for, sta, sto, sto }
and after 1 more character each revealed, set { form, fore, star, stop, stoc }
the new sorted set should {fore, form, star, stoc, stop }
i m hoping complexity o(n) after each new character added, n size of set.
if want in o(n) have somehow keep track of "groups":
for, | sta | sto, sto within groups, can sort strings according last character keeping set sorted.
storing groups can done in various ways. @ first sight, recommend kind of remembering offsets of group beginnings/endings. however, consumes memory.
another possibility might storing strings in kind of prefix-tree, correspond quite naturally "adding 1 char after another", don't know if suitable application.
Comments
Post a Comment