0% found this document useful (0 votes)
26 views5 pages

Final Assingmentpdfcse 373

Uploaded by

araf32277
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

Final Assingmentpdfcse 373

Uploaded by

araf32277
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

x(input) y(time ms)

1000 1007
100000 1013
10000000 1020
100000000 1099

Execution time O(n)


1120

1100
Time Taken in ms

1080

1060

1040

1020

1000
-50000000 0 50000000 100000000 150000000
Input Size

Source Code:
#include <bits/stdc++.h>
using namespace std;

void n_function(){
int n = 100000000;
int cnt = 0;
for(int i = 0; i<n; i++){
cnt++;
}
cout << cnt << "\n";
}

int main(){
auto start =
chrono::high_resolution_clock::now();

this_thread::sleep_for(chrono::seconds(
1));
n_function();
auto stop =
chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::millisec
onds>(stop - start);
cout << "Time taken by function: "
<< duration.count() << "
milliseconds" << endl;
}
x(input) y(time ms)
10000 1004
1000000 1011
100000000 1013
1000000000 1018

Execution Time O(logn)


1020
1018
1016
TIme taken in ms

1014
1012
1010
1008
1006
1004
1002
-2E+08 200000000 600000000 1E+09
Input Size

Source code:
#include <bits/stdc++.h>
using namespace std;

void logn_function(){
int n = 1000000000;
int cnt = 0;
for(int i = n; i > 0; i /= 2){
cnt++;
}
cout << cnt << "\n";
}

int main(){
auto start =
chrono::high_resolution_clock::now();

this_thread::sleep_for(chrono::seconds(
1));
logn_function();
auto stop =
chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::millisec
onds>(stop - start);
cout << "Time taken by function: "
<< duration.count() << "
milliseconds" << endl;}
x(input) y(time ms)
10000 1006
1000000 1036
10000000 1275
100000000 3772

Execution Time O(nlogn)


4000
3500
3000
2500
Axis Title

2000
1500
1000
500
0
0 50000000 100000000 150000000
Input Size

Source Code:
#include <bits/stdc++.h>
using namespace std;
void nlogn_function(){
int n = 100000;
int cnt = 0;
for(int j = 1; j <= n; j++){
for(int i = n; i > 0; i /= 2){
cnt++;
}
}
cout << cnt << "\n";
}
int main(){
auto start =
chrono::high_resolution_clock::now();

this_thread::sleep_for(chrono::seconds(
1));
nlogn_function();
auto stop =
chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::millisec
onds>(stop - start);
cout << "Time taken by function: "<<
duration.count() << " milliseconds" <<
endl;
x(input) y(time ms)
100 1003
1000 1011
10000 1054
100000 4606

O(n^2)
5000
4500
4000
Time Taken in ms

3500
3000
2500
2000
1500
1000
500
0
-20000 0 20000 40000 60000 80000 100000 120000
Input Size

Source Code:
#include <bits/stdc++.h>

using namespace std;

void n2(){

int n = 100000;

int cnt = 0;

for(int j = 1; j <= n; j++){

for(int i = 1; i <= n; i++){

cnt++;

cout << cnt << "\n";

int main(){

auto start = chrono::high_resolution_clock::now();


this_thread::sleep_for(chrono::seconds(1));

n2();

auto stop = chrono::high_resolution_clock::now();

auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);

cout << "Time taken by function: "

<< duration.count() << " milliseconds" << endl;

You might also like