vendredi 11 juin 2021

For Loop With A Function In Condition Statement Time Complexity

What would be the time complexity for these kind of for loops?

Consider the following time complexities fun1 = O(n) and fun2 = O(n).

Example 1:

for(int i = 0; i <= fun1(); i++)
{

     //Something - O(1)

}

Example 2:

for(int i = 0; i <= fun1(); i++)
{

     fun2();

}

Will the time complexity be O(n^2) for the Example 1 and O(n^3) for the Example 2?

Aucun commentaire:

Enregistrer un commentaire