Professional Documents
Culture Documents
Lab Manual
for
Data Structure and Algorithms
(CS 204)
a. d.
int sum,i;
sum = 0; int sum,i,j;
for (i=0;i<n;i++) sum = 0;
sum++; for (i=1;i<n;i=i*2)
{
T(n) = for(j=0;j<n;++j)
Big O= {
sum++;
b. }
}
int sum,i,j;
sum = 0; T(n) =
for (i=0;i<n;++i) Big O=
{
for(j=0;j<n; ++j) e.
{
sum++; int sum,i,j;
} sum = 0;
} for (i=0;i<n;++i)
{
T(n) = for(j=0;j<=i;++j)
Big O= {
sum++;
c. }
int sum,i; }
sum = 0;
for (i=0;i<n;i=i*2) T(n) =
sum++; Big O
T(n) =
Big O=
Experiment analysis:
To find time complexity of a code experimentally we need to calculate the time difference
between starting and ending time of execution of code. So “ctime” library is needed for this
purpose.
#include <iostream>
#include <ctime>
using namespace std;
int main(){
std::clock_t start;
std::clock_t end;
double cpu_time_used;
start=std::clock();
//place your code here
end=std::clock();
cpu_time_used = ((double)(end-start));//CLOCKS_PER_SEC;
cout<<cpu_time_used<<" seconds";
}
Each number present in the Input_Number array above represents a value for “n”
For the codes given in table 1 find the execution time for each value of n given in
the array above.
Then plot separate graphs for time of execution vs. “n”, for all the value of n given in
the Input_numbers array.
Use excel for plotting graph.