I understand how:
for (int i=0; i<n; i++)
This time complexity is O(n).
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
for (k=0; k<n; k++)
this is O(n^3) right?
i=1
do
//......
i++
while (i*2 <n)
Is this O(n)? Or is it exactly O(n/2)?
O(n/2) is O(n) only with a constant coefficient of 1/2. The coefficient can be 10 billion, it would still be O(n), and not e.g. O(n^(1.0001)) which is a different complexity class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With