JAVA Which of these are in increasing order of complexity a
JAVA: Which of these are in increasing order of complexity?
(a) O(n) < O(log n) < O(n^2) < O(n^3) < O(2^n)
(b) O(n) < O(log n) < O(2^n) < O(n^2) < O(n^3)
(c) O(log n) < O(n) < O(2^n) < O(n^2) < O(n^3)
(d) O(log n) < O(n) < O(n^2) < O(n^3) < O(2^n)
Solution
Answer:
d) O(log n) < O(n) < O(n^2) < O(n^3) < O(2^n)
If we check between n^ 3 and 2^n
n^3 2^n
taking log on both sides
log(n^3) log(2^n)
3logn nlog2
chech at higher values of n , n = 128
3 * log(128) 128 *log2
3 * 7 128
21 < 128
means 2^n > n^3
Hence O(n^3) < O(2^n) , with this way we can check for others.
