programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Time Complexity

Greenhorn
Posts: 8
• Number of slices to send:
Optional 'thank-you' note:
Hi guys I have an Algorithm Analysis exam and I was practicing the time complexity and I found this question on the internet.
I tried to solve it but I need you to check if my solution is right or not.

sum = 0 ;
for(i=1; i<=2*n; i++)
sum = sum + 1;

sum = 0 ;
for(i=1; i<=n*n; i++)
sum = sum + 1 ;

sum = 0 :
for(i=1; i<=n; i++)
sum = sum + n ;

sum = 0 ;
for(i=1; i<=n i++)
for(j=1; j<=i; j++)
sum = sum + i ;

sum = 0 ;
for(i=1; i<=n; i++)
for(j=1; j<=n; j*=2)
sum = sum + 1 ;

Ranch Hand
Posts: 954
4
• Number of slices to send:
Optional 'thank-you' note:

sum = 0 :
for(i=1; i<=n; i++)
sum = sum + n ;

It is O(n). . Rest are ok..

Marshal
Posts: 76879
366
• Number of slices to send:
Optional 'thank-you' note:
And welcome to the Ranch

mira pareksha
Greenhorn
Posts: 8
• Number of slices to send:
Optional 'thank-you' note:
hi tushar