Hacker News new | past | comments | ask | show | jobs | submit login

Count the number of nested loops. If one of the loops does splitting (like binary search) it’s a O(log n) as opposed to O(n).

That’s literally all there is to it.




That's not even close to all there is to it. Complexity analysis is a relatively young field with lots of deceptively simple unsolved problems.

For a simple example of how it's a lot more than that, follow Tarjan's proof of the disjoint set's amortized time complexity[0]. It's not at all obvious, even though the disjoint set is a very simple and practical data structure.

[0]: http://www.e-maxx.ru/bookz/files/dsu/Efficiency%20of%20a%20G...


So what would be a deceptivly simple unsolved problem?


Wikipedia has a list of big-name unsolved problems in complexity theory. Most of these have very simple problem statements.

https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_c...


P == NP on analog quantum computers. A light prism performs a diagonalization which can be used to do factorization in O(1).


Factorization of arbitrarily large numbers? I doubt it.


Yes.


On constant-size hardware?

And doesn't getting the data in and out already take O(N)?


Are you talking about arbitrary sized or infinite sized?


We’re saying the time, space, or some other metric of the solution scales with the size of the input number in a way that is not constant. The number could be any input (arbitrary).


That covers most of the algorithms you'll see in a coding interview test, but there's a ton more complexities outside of search spaces, sorts and nested O(n) loops.

Even some graph operations will leave familiar territory.


Strassen algorithm is 7-multiplications for a 2x2 matrix. https://en.wikipedia.org/wiki/Strassen_algorithm

A matrix can always be split into groups of sub-matrix, and the groups of sub-matrix is itself a matrix. Applying Strassen algorithm recursively is therefore O(n^log2(7)) == O(n^2.8ish).


The article covers none of those.


What if there are recursive function calls?


Then you get to have fun solving a recurrence relation. :-)


If you don't like "fun", WolframAlpha can solve those for you. :-)

https://www.wolframalpha.com/input/?i=f%281%29+%3D+1%2C+f%28...


Sure, but if you're not on the spot in an interview, the master theorem is simple enough to apply: https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_al...


Thank you, but for the link provided it only says that these are the Fibonacci numbers and nothing more. Yes, you can click on this F(n) (how can you even know this is a link), but anyways.


branchesᵈᵉᵖᵗʰ




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: