I vote for O(n log n)

Hello,

  1. For O(n^2) the number of comparisons you would have to do for a six-letter word would be 15.
  2. For O(n) the number of comparisons you would have to do is 26+n, which in this case is 6, so 32 because you have to compare the guess letters to the entire alphabet.
  3. For O(n log n), where n = 6, the number of comparisons would be 4.66 or about 5.

Clearly, O(n log n) is better because you have to do fewer comparisons. Of course, this is only because n is such a small number and will remain that way for the entire playthrough. Fortunately, we have already coded measures in place to stop guess from being longer than 6 letters.
Hopefully, my understanding is correct…

Thanks,
Enrico

i agree but simply because O (n) for checking is only reliable if repeating letters are next to each other in unsorted string. To fix this you need to sort it so that repeating letters are next to each other. The sort time is O(n log n)

Privacy & Terms