Reputation: 3
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
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