 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Member Join Date
May 2004
Posts
249

## Testing Time Complexity

Well this is my homework question. But it is not graded

I am to find the time complexity of the below So i came up wtih the following:

Code:
```#include <iostream>

using namespace std;

int main()
{

int k = 1;
int n = 0;

cout << "please enter n: ";
cin >> n;
cout << endl << endl;

for (int i = 0; i < n; i++)
{
k = k * 2;
for (int j = 0; j < k; j++)
cout << /*"j = " << j << "\t"*/ endl;
cout << "k = " << k << "\t";
}

return 0;
}```
The results are as follows My question is, what is the figure/number that would go into the third column?

I found out that k = 2^n
but i need to find out T(n)  Reply With Quote

2. Member Join Date
May 2004
Posts
249

## Re: Testing Time Complexity

I will formulate my own equation. I just need a few figures to get going  Reply With Quote

3. Banned  Join Date
Jun 2015
Posts
208

## Re: Testing Time Complexity Originally Posted by rockx I found out that k = 2^n
but i need to find out T(n)
Well if T(n) is the actual number of iterations then you should sum up all k's from 0 to n. You get,

T(n) = 2^0 + 2^1 + 2^2 + 2^3 + ... + 2^n = 2^(n+1) - 1  Reply With Quote

4. Member Join Date
May 2004
Posts
249

## Re: Testing Time Complexity

thanks T  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
• 