asymptotic complexity - How to we find a Tight Big O expression -
for(i: 1 n^2) x = x + 1; return x + 1;
n number of inputs. n>1 , tends infinity understand worst (and best) case running time n^2 + 1
. hence, it'll o(n^2)
. however, how find if tight, big o expression? how find tight big o expression? that?
let function f(n)
you worked out best case n^2 (ommit +1 since constants indepently input ignored).
more formally: Ω(n^2) --> means can find function u(n) , constant k such k * u(n) <= f(n) in terms of complexity.
as said worst case n^2 too. again formally: o(n^2) --> means can find function v(n) , constant k such k * v(n) >= f(n) in terms of complexity.
since Ω , o sets of functions theta defined intersection of Ω , o. "theta upper , lower bound."
the intersection n^2 --> theta (n^2)
in descriptive manner:
f(n) grows not faster (or equal) u(n). f(n) grows not faster (or equal) v(n). --> f(n) grows n^2
keep in mind mor Ω , o sets of different classes of functions.
e.g. Ω(log n)(searching in tree) , o(n) (searching in string) when dealing such case unable specify exact theta value.
Comments
Post a Comment