I've written a function append()
in Java and I need to analize its runtime complexity by O(N) and Θ(N).
This is the original question:
Suppose
append()
's runtime complexity ist = O(N)
, it's mean thatt
can also be represented byt = C*N
. (asC
is a constant)Therefore
(t / N) = C
.If, for example,
t = O(N^2)
, then(t / N^2) = C
and so on.use this method to find
append()
run time coplexity.
So I ran append()
N times for 3 different N
s: 1,000
, 5,000
, 10,000
.
long start = System.currentTimeMillis();
for(i = 0; i < N; ++i) {
append();
}
long end = long start = System.currentTimeMillis();
System.out.println(end - start);
and I wrote down end-start
which is the runtime in milliseconds.
Now, how can I use this info in order to get the time coplexity of append()
?
Thanks in advance!