GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Nov-2008, 01:27
faisaly faisaly is offline
New Member
 
Join Date: Feb 2008
Posts: 9
faisaly has a little shameless behaviour in the past

Algorithm in C++


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

CPP / C++ / C 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;
}
Last edited by admin : 10-Nov-2008 at 02:14. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 10-Nov-2008, 02:12
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Re: Algorithm in C++


its n^2.

please use [ CPP ][ /CPP ] tags next time you post code
  #3  
Old 10-Nov-2008, 07:51
cpit cpit is offline
Junior Member
 
Join Date: Jan 2006
Posts: 73
cpit is on a distinguished road

Re: Algorithm in C++


Given that you have two nested loops, and that i and j loops n times, you have n^2.
  #4  
Old 11-Nov-2008, 03:55
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Algorithm in C++


This can be expressed as O(N^2);
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Array Passing/Kmeans Algorithm chongl C++ Forum 3 14-Jul-2007 19:39
Binary search algorithm CaCao C Programming Language 3 01-Apr-2007 04:42
Algorithm Help Please! daking_09 C++ Forum 0 24-May-2006 20:12
balloon park puzzle algorithm husny Computer Software Forum - Games 0 14-Mar-2006 17:29
Simple Encryption Algorithm aaroncohn C Programming Language 17 03-Mar-2004 16:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:00.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.