0% found this document useful (0 votes)
5 views

Assignment 2

The document discusses an assignment on analyzing algorithm complexity. It provides 9 code fragments and asks students to determine the runtime complexity and Big-O notation for each. It specifies the assignment must be done in groups of 4-6 students, with each contributing, and that sharing answers between groups is considered cheating.

Uploaded by

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

Assignment 2

The document discusses an assignment on analyzing algorithm complexity. It provides 9 code fragments and asks students to determine the runtime complexity and Big-O notation for each. It specifies the assignment must be done in groups of 4-6 students, with each contributing, and that sharing answers between groups is considered cheating.

Uploaded by

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

HiLCoE School of Computer Science and Technology

Assignment 1(Algorithm complexity analysis)


1. For the Following code fragment determine the run time complexity and
its Big–O representation.

a. sum=0;
while(x>0){
if(x%2==0){
x++;
sum +=x%10;
}else
sum +=x%10 +1;
x=x/10
}
return sum;

b. for (int count = 0, i = 1; i < =N;i*=2){


for (int j = 1; j <= i; j++){
count++;
}}

c. int sum= 0;
for (i = 1; i <= n * n - 10; i++)
for (j = 1; j <= i; j ++)
sum += j;

d. int sum = 0;
for (i = 1; i <= n; i *= 2)
for (j = 1; j <= i; j++)
sum += j;

e. int counter = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j += i)
counter++;

f. int counter = 0,sum = 0;


for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j += i)
sum += j
for (j = 1; j <= i; j++)

1
HiLCoE School of Computer Science and Technology

counter++;
}

g. int count = 0;
void f(int n) {
if (n == 0) return;
for (int i = 0; i < n; i++)
count++;
f(n-1);
}

h. int sum = 0;
void f(int n) {
if (n == 0) return;
sum += 1;
f(n-1);
f(n-1);
}

i. int counter=0;
void f(int n) {
if (n == 0) return;
for (int i = 0; i < n; i++)
counter++;
for (int i = 0; i < 4; i++)
f(n/4);
}

Important:
It’s a group assignment (max. of 6 members and min. of 4 members)
Each member of the group must participate on the work.
Exchange of any answer between groups is considered as a
cheating. Both group will not receive any credit from the
assignment
Finally, submit your assignment question with answers in pdf.
Assignment due date: March 16, 2024 12 p.m.

You might also like