Note: you could make the procedure a lot smarter, but that's only needed if you use a lot of duplicate characters in a word. I now use the sorted/duplicates properties of tstringlist to remove the unwanted entries. This could be inserted into the algorithm. Since this thing is building a tree, it could take a long while to complete for large words. You may experience stack overflows and such.