You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
private HashSet<string> Edits(string word, int editDistance, HashSet<string> deleteWords)
{
editDistance++;
if (word.Length > 1)
{
for (int i = 0; i < word.Length; i++)
{
string delete = word.Remove(i, 1);
if (deleteWords.Add(delete))
{
//recursion, if maximum edit distance not yet reached
if (editDistance < maxDictionaryEditDistance) Edits(delete, editDistance, deleteWords);
}
}
}
return deleteWords;
}
Would it make sense to only add to calculate and add the words to deleteWords if editDistance < maxDictionaryEditDistance is true? That is quite a difference in loading dictionary performance. It does change the functionality, but isn't that the correct approach not to add the words anyhow?
The text was updated successfully, but these errors were encountered:
I think we already do exactly this. Edits is a recursive method.
Only in the first iteration we unconditionally calculate and add deletes.
That is because we always have maxDictionaryEditDistance>=1.
But the second and following iterations of Edits are done only if editDistance < maxDictionaryEditDistance.
Yes, what I meant, that when editDistance == maxDictionaryEditDistance, we do add the delete word, but not call the recursion anymore. I was wondering if we need to add the delete word at all at this case, but now that I pondered on it more, I think it is intentional, right? That case should still be included, just not going anymore deeper with the recursion.
In the following function:
Would it make sense to only add to calculate and add the words to
deleteWords
ifeditDistance < maxDictionaryEditDistance
is true? That is quite a difference in loading dictionary performance. It does change the functionality, but isn't that the correct approach not to add the words anyhow?The text was updated successfully, but these errors were encountered: