Hey, I have improvised the initialize function. The previous implementation was taking a lot of time due to unnecessary searching for 'word' if present in 'nd'. In time complexity terms, it was taking O(n) time for every outer iteration. Whereas we can do that part in O(1) time.
Test it out by taking a huge corpus, In that case, you will see a lot of time difference.
And, this time difference matters a lot for searching.
Hey, I have improvised the initialize function. The previous implementation was taking a lot of time due to unnecessary searching for 'word' if present in 'nd'. In time complexity terms, it was taking O(n) time for every outer iteration. Whereas we can do that part in O(1) time.
Test it out by taking a huge corpus, In that case, you will see a lot of time difference. And, this time difference matters a lot for searching.