Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Assignment I

Uploaded by

dagimnega66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Assignment I

Uploaded by

dagimnega66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PARADISE VALLEY UNIVERSITY COLLEGE

DEPARTMENT OF COMPUTER SCIENCE

Assignment (I) for Data Structure and Algorithms

Part I-Introduction to Data Structures and Algorithms

1. Write a C++ program that displays the total running time of a given algorithm based on
different situations such as processor speed, input size, processor load, and software
environment (DOS and Windows).
2. Calculate the T(n) with big O for the following fragment of codes: (Warning: Please
show necessary steps).
For example:
for (int i=1;ji<=n;i++)
cout<<i;
T(n)=1+n+1+n+n
= 3n+2
T(n)=O(n). This indicates as T(n) is big O (or O(n))

a. int sum=0, n, m;
for(int=1;i<=n;i++)
for(int j=1;j<=m;j++)
Sum++;
b. int sum=0, i, j, n;
for(i=1;i<=n;i++)
for(j=1;j<=i;j++)
sum++;

INSTRUCTOR: MELKAMU A. 1
c.
for (int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
Cout<<i;

d.
for(int i=1;i<=n;i++)
int Sum=sum+i;
for (i=1;i<=n;i++)
for(j=1;j<=m;j++)
Sum++;
e.

if(k==1)

{
for (i=1;i<=100;i++)
for (j=1;j<=1000;j++)
Cout<<I
}
else if(k==2)
{

for(i=1;i<=n;i=i*2)

Cout<<i;

}
else
{
{for (i=1;i<=n;i++)
Sum++;
}

INSTRUCTOR: MELKAMU A. 2
f.
for (i=1; i<=n;i++)
{
If (i<10)
for(j=1;j<=n;j=j*2)
cout<<j;
Else
cout<<i;
}

g.

void Algorithm_Analysis( int n){

for(int i =0 ; i < n ; i= i*4){

for(int j = n ; j > 2; j = j/3){

cout<<“This is about algorithm analysis with order of magnitude”;

INSTRUCTOR: MELKAMU A. 3
Part II-Searching and Sorting Algorithms

3. Write a C++ program that will implement all of the sorting algorithms. The program
should accept different unsorted data items from user and sort using all algorithms and
should tell which algorithm is efficient for that particular unsorted data items. (Hint: use
how many comparison and swaps are done so the one with the less number of swap and
comparison number is considered as an efficient algorithm for that particular data items.)

Notice

Issue Date: 29/10/23

Submission Date: 07/11/23

Concerned Body: Individual (it is individual assignment)

INSTRUCTOR: MELKAMU A. 4

You might also like