I have an array of dictionary words and a random string like “twowords”
What is the fastest way to check if the entire string is made up of dictionary words? so “twojwords” would return false and “twowords” returns true
I was using a binary search before but it couldn’t handle two word strings
(I’m using objective c)
Here’s a naive approach, but I don’t know if there is a faster way.
For this, you need to be able to form a substring of letters a to b of the string. E.g. if
string = "thisisastring"thenstring[4..7] = "isas". You also need a boolean function inDictionary, which should do a binary search for the substring in the dictionary.This method will work, but depending on the size of the dictionary, may take a bit of time. I believe the English language is currently around 200000 words, in which case any reasonable programming language should have reasonable performance.