user8140261
user8140261

Reputation: 3

Time complexity pseudo code

I want to calculate the time complexity of the following code :

for(i=0;i<n;i++){
    func();
    .            // Other O(1) operations
    .
}

where func() has a complexity of O(k).

Upvotes: 0

Views: 323

Answers (2)

codecrazer
codecrazer

Reputation: 535

You should realize the meaning of loop, if you use

for(int i=0;i<n;i++)

The loop will be executed n times, and every times, one loop will cost O(k)+O(1)=O(k), so the total complexity will be O(n*k), hope this post help you!

Upvotes: 1

Yuval Ben-Arie
Yuval Ben-Arie

Reputation: 1290

The time complexity will be O(k*n) then.

Upvotes: 0

Related Questions