Lecture BullCow Isogram algorithm is inefficient

I noticed the resulting algorithm for determining if a word is an Isogram is (I think ???) O(n^2) in terms of complexity. We can make it O(n) by simply using a map. Nesting for loops within for loops is rarely ever a good idea so I decided to write the function my own way using a map. I haven’t finished the lecture yet so I don’t know if the instructor actually goes over this, but I think efficiency is a very important thing to think about and training new game devs to use nested for loops might hurt their development skills.

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    std::map<char, bool> letters;

    for (int32 i = 0; i < Word.Len(); i++)
    {
        if (letters[Word[i]] == true)
        {
            return false;
        }

        letters[Word[i]] = true;
    }

    return true;
}

Privacy & Terms