954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Algorithm in C++

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

#include
#include
using namespace std;

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

faisaly
Newbie Poster
21 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Well, you demonstrate absolutely senseless code (n is not initialized).
And what's your question?

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

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

#include #include using namespace std;

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

Code tags please[code=cplusplus][/[TEX]][/TEX]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

#include<iostream>
#include<cstdlib>
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;
}

But indeed agreein with ArkM what is n?

Chris

Freaky_Chris
Master Poster
702 posts since Apr 2008
Reputation Points: 325
Solved Threads: 118
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You