1
#include <iostream> 
using namespace std; 
for(int i=1;i<n;i++) 
{ 
      for(int j=1;j<n;j+=i) 
      { 
        //Some O(1) Code 
      } 
} 

What is the time complexity of this code. Note: The increment in second loop is j=j+i.

This is what I understand so far: When i=1, second loops runs n times when i=2, second loops runs n/2 times and so on

So, this is what we have: n+ n/2 +n/3 + ... + 1 Now, how do we find the time complexity from here?

HARSHIT DANG
  • 21
  • 1
  • 5

0 Answers0