Up until the challenge, my vote is for O(n^2)

Because for a list of letters in a word, it won’t go far above 13-15 letters anyway AND it is simpler than the other options, and more efficient than O(n).

Feedback would be very appreaciated.

The way to write the code for IsIsogram is definitely easier to write the O(n^2) version for sure, but it isn’t more efficient.

You would save time writing the code, but the execution may take longer. Even at 13 letters the check would have to happen nearly 150 times to verify the word is an isogram. If you use the O(nlog(n)) version you have to add the O(n) for the actual check, but for 13 letters you’re looking at maybe 50. That’s way faster…

However, I think your point is that this is such a simple project that the 150 vs 50 comparison is meaningless. A computer can do 50 iterations in milliseconds so 3 times x milliseconds is really only max a second and we can wait a second for this. Which is fair enough.

Good to think about though.

It comes down to knowing when to do the work yourself vs. offloading the work to the computer. When your application is a game using free cycles on a desktop computer and you’re comparing dozens vs. hundreds of operations the differences are purely academic.

If your algorithm is the google page ranks algorithm, every cycle of the CPU is precious $$$$$. Spending thousands of man-hours to save a single operation would probably pay-off, given the obscene number of times each second that code is churning around the globe… Not only wasted heat and power, but also wasted time and every millisecond counts at that scale.

Privacy & Terms