943,697 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 876
  • C++ RSS
Nov 10th, 2008
0

Algorithm in C++

Expand Post »
Considering the given code as an algorithm calculate the time complexity of this code.

#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
int i, j, n;
for(i=0;i<n; i++){

for(j=0; j<n; j++){
cout<<"my time complexity is = "<<i*j<<endl;
}
cout<<"complexity is increasing"<<j<<endl;
}
system("pause");
return 0;
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
faisaly is offline Offline
21 posts
since May 2007
Nov 10th, 2008
0

Re: Algorithm in C++

Well, you demonstrate absolutely senseless code (n is not initialized).
And what's your question?
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 10th, 2008
0

Re: Algorithm in C++

Click to Expand / Collapse  Quote originally posted by faisaly ...
Considering the given code as an algorithm calculate the time complexity of this code.

#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
int i, j, n;
for(i=0;i<n; i++){

for(j=0; j<n; j++){
cout<<"my time complexity is = "<<i*j<<endl;
}
cout<<"complexity is increasing"<<j<<endl;
}
system("pause");
return 0;
}
Code tags please [code=cplusplus][/]code]. Also if our asking what the time complexity is. Why don't you consider showing us what you understand before we just tell you.

Also it should be cstdlib, since this is cplusplus

C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.  
  5. int main(){
  6. int i, j, n;
  7. for(i=0;i<n; i++){
  8.  
  9. for(j=0; j<n; j++){
  10. cout<<"my time complexity is = "<<i*j<<endl;
  11. }
  12. cout<<"complexity is increasing"<<j<<endl;
  13. }
  14. system("pause");
  15. return 0;
  16. }

But indeed agreein with ArkM what is n?

Chris
Last edited by Freaky_Chris; Nov 10th, 2008 at 4:40 am.
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How can I register COM Compnent in VC++
Next Thread in C++ Forum Timeline: Flexie Programming Assignment





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC