Another Vote for O(n)

I tend to agree for with those people who have suggested that the most efficient way of checking for an isogram is by stepping through the word one letter at a time, checking against an array of 26 elements whether that letter already exists, and updating the array if not.

for (I = 0; I < Guess.length(); i++)
{
if (Alphabet[Guess[i]-‘a’])
{
return false;
}
else
{
Alphabet[Guess[i]-‘a’] = true;
}
}
return true;

This is O(n), and the graphs have shown us that O(n) is better than O(n^2) or O(nlogn).

Privacy & Terms