Implementing a simple Trie for efficient Levenshtein Distance calculation - Java

后端 未结 11 836
不思量自难忘°
不思量自难忘° 2020-12-22 18:51

UPDATE 3

Done. Below is the code that finally passed all of my tests. Again, this is modeled after Murilo Vasconcelo\'s modified version of Steve

11条回答
  •  借酒劲吻你
    2020-12-22 19:35

    Correct me if I am wrong but I believe your update3 has an extra loop which is unnecesary and makes the program much slower:

    for (int i = 0; i < iWordLength; i++) {
        traverseTrie(theTrie.root, word.get(i), word, currentRow);
    }
    

    You ought to call traverseTrie only once because within traverseTrie you are already looping over the whole word. The code should be only as follows:

    traverseTrie(theTrie.root, ' ', word, currentRow);
    

提交回复
热议问题