OK, so there is more to Tries than I thought

I thought that I had done with tries….. but I was wrong.  I chanced upon a subtle refinement which makes the solution even more general. To save repeating myself I will assume that you have read my previous posts about tries.

Instead of indexing the tries with an Iterator<Integer> I have modified the code to use Iterator<Comparable>.  It still works with Iterator<Integer> as Integer implements Comparable.  The advantages are significant.  For example you could index sentences by the contained words…. it was this question in StackOverflow that prompted me.

Now you can create tries that are indexed by any type at all as long as that type implements comparable.  Ordered lists of playing cards, steps in martial arts routines, key sequences on a keyboard – your imagination is the only limit.  What you get is an order-N insertion/retrieval of a sorted set.

 

Leave a Reply

Your email address will not be published. Required fields are marked *