368 views
1 votes
1 votes
for ( i= 1; i<=n; i++)
      for(j=n/3: j<=2n; j=j+n/3)
                sum =sum+1;
                

What will be O and θ for this

1 Answer

2 votes
2 votes
Outer loop will run for n times and inner loop will run for 6 times only (n/3, 2n/3, n, 4n/3, 5n/3, 2n)

Hence average case $\Theta$(n) and worst case will be >=O(n)

Related questions