How to find Time Complexity of an Algorithm?
Code to Big 0 notation
Big 0 notation:
Here are some highlights about Big O Notation:
Big O notation is a framework to analyze and compare
algorithms.
Amount of work the CPU has to do (time complexity) as the
input size grows (towards infinity).
Big O = Big Order function. Drop constants and lower order
terms. E.g. O(3*n^2 + 10n + 10) becomes O(n^2).
Big O notation cares about the worst-case scenario. E.g.,
when you want to sort and elements in the array are in
reverse order for some sorting algorithms.
Sequential Statements
1 statement1;
2 statement2;
3 …
4 statementN;
Let’s use T(n) as the total time in function of the input size n,
and t as the time complexity taken by a statement or group of
statements.
T(n) = t(statement1) + t(statement2) + ... + t(statementN);
Code to Big 0 notation
Big 0 notation:
Here are some highlights about Big O Notation:
Big O notation is a framework to analyze and compare
algorithms.
Amount of work the CPU has to do (time complexity) as the
input size grows (towards infinity).
Big O = Big Order function. Drop constants and lower order
terms. E.g. O(3*n^2 + 10n + 10) becomes O(n^2).
Big O notation cares about the worst-case scenario. E.g.,
when you want to sort and elements in the array are in
reverse order for some sorting algorithms.
Sequential Statements
1 statement1;
2 statement2;
3 …
4 statementN;
Let’s use T(n) as the total time in function of the input size n,
and t as the time complexity taken by a statement or group of
statements.
T(n) = t(statement1) + t(statement2) + ... + t(statementN);