Time complexity for O(n) and O(2^n)

I'm trying to figure out the time complexity associated with O(n) and O(2^n) when the values for n are 100, 1000, 10000, and 100000 regarding O(n), and 5, 10, 15, 20, 25, 30 when trying O(2^n). Running each value of n independently is fine, as I am going to create a table to show the different run times. But I seem to be stuck in some type of loop, or just have incorrect code. If anyone sees a red flag in my code, would you please point me in the right direction? Thanks!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <ctime>
#include <time.h>
#include <string>
using namespace std;

double calc_func_run(double x, double n);
double calc_func_run_again(double x, double n);

int main()
{
	time_t start, end;
	double n;
	double dif;
	double x = 2;
	time(&start);
	cout << "Enter the value of 'n': ";
	n = 5;

	//cout << calc_func_run(x, n) << endl;
	cout << calc_func_run_again(x, n) << endl;
	time(&end);

	dif = difftime(end, start);

	cout << "It took " << dif << " to run the process when n was " << n << "!" << endl;
	return 0;
}

double calc_func_run(double x, double n)
{
	long double ans = 1;
	for (double i = 1; i <= n; i++)
	{
		ans = ans * x;
		cout << ans << endl;
	}
	return 0;
}

double calc_func_run_again(double x, double n)
{
	int j, k;
	double power = 1;
	for(j = 1; j < n; j++)
	{power = power * 2;
	for(k = 1; k < power; k++)
	{
		cout << k << endl;
	}
	}
	return 0;
}
Topic archived. No new replies allowed.