Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

Thanks, I will use Theta(N) next time. There are a bunch of complexity notations, omega, theta, o, etc. I need to brush up on them [1]

[1] http://www.youtube.com/watch?v=6Ol2JbwoJp0



It's still worth noting, as others have, that there's a huge assumption baked in to your estimate: that all operations are created equal when it comes to execution time.

If we're going to talk "practically" here :) things like branch prediction will ensure that nothing like 2x the execution time will be spent on just the double conditional.

Meanwhile, what you do inside that loop becomes much more important to the time estimate than the conditional (.length is a fast single property lookup, whereas just accessing a value in the array (which is presumably the purpose of this method) will often trigger a bounds check on length, then an offset into a looked-up offset into memory, etc).

So it's not really worth doing for speed. All that said, I think yours reads better anyway.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: