Interview Question
Country: India
a) 22n = O(n)
b) 2n2 = O(n) (or if it's 2^n * 2, then O(2^n), or if it's 2 * n^2, then O(n^2))
c) n2log(n) = O(n log(n)) (or if it's n^2 log (n), then O(n^2 log (n))
d) n = O(n)
e) n2n = O(n^2) (or if it's n^2 * n, then O(n^3)
log(n) = O(n^a) for any a > 0, so n * log (n) grows faster than n, but slower than n^2.
Any sort of exponential function grows faster than any power of n, so 2^n grows the fastest.
To encompass all possibilities, here is the order of growth in increasing order
n, 22n
n * log (n)
n^2, 2n^2
n^2 * log (n)
n^3
2^(n+1)
Your notation is atrocious.
Arrange the following growth rates in increasing order:
O (3n), O (n2), O (1), O (n log n)
1) O(1) - bounded function
2) O(3n) = O(n) - linear function
3) O(n log n) - when comparing n log n and n^2, note that log n is not bounded. However, any exponent of n grows faster than log n, so for some constant C > 0 and large enough n, log n <= C * n, and so n log n <= C * n^2 for some C > 0 and n > N for some N
4) O(n^2)
Ans for IGNOU Assignment MCS031 Question:7
1) O(1) - bounded function
2) O(3n) = O(n) - linear function
3) O(n log n) - when comparing n log n and n^2, note that log n is not bounded. However, any exponent of n grows faster than log n, so for some constant C > 0 and large enough n, log n <= C * n, and so n log n <= C * n^2 for some C > 0 and n > N for some N
4) O(n^2)
Arrange the following functions in increasing order of growth rate (with g(n) following f(n) in your list if and only if f(n)=O(g(n))).
a)n
b)10n
c)n1.5
d)2log(n)
e)n5/3
Big O notation.
- howaboutthis March 26, 2012my bet would be n, 22n, n^2 log(n), 2*n^2, n^2*n;