lundi 27 février 2017

Time complexity relation to input, and nest for loops

In this for loop, the time complexity would be o(x) or o(n)

for(int i =0, i<x, i++)

say X is now

int x = 2^b

where b is an input, this would change the time complexity to o(2^x) or o(2^n)?

I want to confirm if my understanding of time complexity is valid. If so, a follow up question would be that when the initial for loop has a nested for loop, it would change the time complexity again to o(2^n * n) ?

int x = 2^b
for(int i =0; i<x; i++)
   for(int j = 0; i<z; j++)

Aucun commentaire:

Enregistrer un commentaire