How to find find the longest common prefix to a string in a Trie?
Erdogan Seref <[email protected]> Fri, 2 Aug 2024 15:53:11 +0200
| Newsgroups | gmane.comp.jakarta.commons.user |
|---|---|
| Message-ID | <CAFMcyF4W3J1QoWq-39dPCh7AaoSnK0-0W4ACk4DFL+TpASoYmw@mail.gmail.com> |
Hello, I want to implement a method called findLongestCommonPrefix(Trie<K, V> trie, K value). This method should return the longest key of the trie that is a prefix of value. For example, if the Trie contains 'Anna', 'Anael', 'Analu', 'Andreas', 'Andrea', 'Andres', and 'Anatole', then a lookup of 'Andreasov' would return 'Andreas'. The current method prefixMap does the reverse. How can I implement this method using the methods of the Trie interface? Kind regards Erdogan Seref