Lecture 45 challenge

I believe the best sorting method would be O(n log n) because the O(n) would be impractical since it is only comparing one letter to the next letter and would miss duplicate words as compared to O(n log n) which would sort and then compared one letter to the next. The O(n^2) would work but the PC would take a much longer time to reach a result. Hope I said this right. Have a great day everyone.

I agree. On Wolfram Alpha, I found that the graphs of O(n) and O(n^2) overlap when n gets high enough. For small numbers, I found that O(n) may be quicker, but for larger values of n, O(n Log n) takes the lead in speed. And yeah, O(n^2) is much, much slower than the other two.

I agree too, O(n log n) would be much faster and will also work in any case, no matter how high n is. O(n) maybe Quicker for our case.
Vote for O(n log n) or O(n)
EDIT:- What about O(log n), Binary Search? It is much faster than O(n)…

You can only do binary search on an input that is already sorted :wink:

I believe the best you can go is O(n). Assuming all characters are english letters and they are all lowercase you can use my solution.

Solution:

  • Initialize an array of size 26.
  • go for each letter of the Isogram.
  • if the index of that character is >= 2 then the word is not a Isogram.
  • if you couldn’t find a not isogram then it must be a isogram.

link to the code.

Still you need to sort and do a binary search for each letter. It will end like this: O(n log n) + n * O(log n).

Privacy & Terms