New answers tagged complexity
As written, it's O(1) because you do nothing in the loop. The compiler will optimize it away.
It is O(n/2)=O(n), since complexity is calculated in order of magnitude and constants can be "ignored". So, if c is a constant : O(c*n)=O(n) O(c*logn)=)(logn) etc.
As written, it's O(n) i.e. if you double the size of n it'll take twice as long. Any half decent compiler/JIT will, however, spot that it doesn't do anything and strip it out i.e. O(0). But I presume that's not what you're after.
O(n) since if n is extremely large (close to infinity), the fact that it is divided by two is negligent.
Your code doesn't allocate any objects, nevertheless it has O(n) space complexity. Whenever you call your method, the implementation will set up a call stack frame. At the least, this includes the return address, but in this case you will also need stack space for the parameters and any local variables. Even if a variable points only to null or to existing ...
(The following answer uses SQL Server RDBMS to explain) First off, there are no temporary tables in your question. Temporary tables (in SQL Server) are actual tables that live in tempdb, and are defined with one or two pound signs (#) preceding it. What you have is a simple alias (temporary_data). Two extremely different things. That is an extremely ...
Top 50 recent answers are included