This is day 1 of my 100 days coding challenge and today I have learned about time complexity. Today I got to know why we need to know time complexity as it helps us to compare two or more algorithms. One of the biggest misconceptions about time complexity is that many people think that it is the time taken by your algo but this is not the case because your running time is system dependent. So instead of running time, we start to count the number of processor operations. For example, for an assignment, we standardise the processor operation to 1 and similarly for comparison, arithmetic etc.
But after some time we realize that the processor operation depends on your input size. From all this, we can now define the Time complexity (T(n)), it is a function of n which provides us with the processor count. For example, T(n)=6n+14 where n is the input size and your 6n+14 is your processor count.
Big O notation
Big o notation is used to classify the various Time complexities for example if we have T1(n)= n^2+6n+19 and T2(n)= 3n^2+17n+33 in this highest degree is n^2 we classify it as O(n^2).
O(g(n)) = f(n) where f(n)<=c*g(n)
in this your c*g(n) acts as your upper bound.
we can also perform two operations on it addition and multiplication.
O(f(n))+O(g(n) = O(f(n) if O(f(n))>O(g(n)) else O(g(n))
By-:
Pranav Sharma