Also called DAWGs (Directed Acyclic Word Graphs [1]).  John Resig blogged about a similar problem 5 years ago, for which I wrote a JavaScript solution [2].<p>[1] <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Directed_acyclic_word_graph" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Directed_acyclic_word_graph</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;mckoss&#x2F;lookups" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mckoss&#x2F;lookups</a>