Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
.
Theoretically, it's true
But in practical...
Yes, something that runs in
26n
is 26 times slower than something that runs inn
.However, when talking about big O notation, that doesn't make a difference. There exists a C>0 for which they are both always faster than
C*n
. This means that by definition, they are both part of O(n).This is why big O isn't always the be all end all. It's applicability always depends or your application. If
n+26
would run in a day,26n
would need 26 days, but an^2
algorithm could very well need a year to accomplish the same and2^n
could take a millennium.If you compare something up to infinity, "26 times slower" is insignificant and can be neglected.
Oh I see,
but still O(26n) is much worse than O(n+26)
No it isn't.
indexOf
is called a fixed amount of times. The length of the alphabet does not increase when the input length increases.@XoRMiAS
You forget indexOf is O(n)
So total is O(n^2)
In terms of big O notation, this has the same performance as basically all other solutions: O(n).
BAD Performance