Hi,

For this, we can assume these strings to be numbers in base say 36, then convert these to base 10 and sort these so basically means assigning weighted values to all these characters.
e.g.

ab = 11 + 10*36 = 371
and
bc = 12 + 13*36 = something

now, the glitch here is what if we have "bac" and "ca" the weighted value for bac will be more than ca but ca should have more value as per our definition of the ordering, so for this purpose, we convert all strings to same length that is of the biggest string (here, I am assuming we know the length of the longest string, even otherwise we can calculate this in one pass). We add a special character, say $ which has a weighted value of 10.
so ca becomes ca$, hence a value more than that of bac. I think this should work fine.

By doing this, we basically save time in comparing the strings again and again which is a time consuming process (atleast in comparison to integer comparison)

Let me know ur thoughts about this.

-Vijju

On 10/10/06, raja <[EMAIL PROTECTED]> wrote:

There will be no aa, ba etc.

Suppose there is a file where there are some words like abc, dac, ru,
cat, act.
Now the program will check these and if the word is in proper
lexicographic order, it will replace the word with the number and
otherwise, delete the word.

The numbering will be as said above. that is the next correct
lexicographic word will get the next integer. here only abc, ru and act
will be given numbers.






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to