I have been doing some self-study on Big-O. I understand how to give examples of the following notations to algorithms:
O(N):
for(int i = 0; i < n; i++)
sum++;
O(N^2):
for(int i = 0; i < n; i++)
for( int j = 0; j < n; j++)
sum++;
O(N^3):
for(int i = 0; i < n; i++)
for( int j = 0; j < n * n; j++)
sum++;
I have come across these notations which I don't quite comprehend. How do I give examples of these in terms of algorithms?
Maybe I should phrase it this way: write an algorithm which takes running time in proportion to:
- O((n^3)/4)
- log n^3
- O((log^2)n)+O(n)
- 4^n
- n^3/2