Assignment 1
Assignment 1
1) main ()
{
int x, y, z, i,n;
x=y+z;
for(i=1;i<=n,i++)
{
x=y+z
}
}
2) main ()
{
int x, y, z, i,j, n;
x=y+z;
for(i=1;i<=n,i++)
x=y+z
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
x=y+z;
}
}
}
3) main ()
{
int x, y, z, i,j, n;
x=y+z;
for (i=1 to n)
x=y+z
for (i=1 to n)
for (j=1 to n/2)
x=y+z;
}
4) main ()
{
int x, y, z, i,j, k,n;
for (i=1 to n)
for (j=1 to i)
for (k=1 to 135)
x=y+z;
}
5) main ()
{
int x, y, z, i,j, k,n;
for (i=1 to n)
for (j=1 to 𝑖 2 )
for (k=1 to n/2)
x=y+z;
}
6) main ()
{
int x, y, z, n;
x=y+z;
while(n>1)
{
x=y+z;
n=n/2;
}
}
7) main ()
𝑘
{𝑛 = 22
for (i=1; i<= n;i++)
j=2;
while (j<=n)
for (k=1 to 135)
𝑗 = 𝑗 2;
}
9) Consider algorithm A, which tackles problems by breaking them into five subproblems,
each of size half the original. It recursively solves each subproblem and then combines
the results in linear time. What is the time complexity of this algorithm?
10) Algorithm B addresses problems of size n by recursively solving two subproblems,
each of size n - 1, and then merging the solutions in constant time. What is the time
complexity of this algorithm?
11) Algorithm C solves problems of size n by dividing them into nine subproblems, each
of size n/3, recursively solving each subproblem, and then merging the solutions in
O(n²) time. What is the time complexity of this algorithm?
12) Given an array, provide an algorithm to find the maximum and minimum values.
Analyse the algorithm using time and space complexity.
13) Write a recursive C-Program and recurrence relation to find the factorial of n.
14) Write a recursive C-Program and recurrence relation to find the multiplication of 2
positive numbers m and n.
15) Write a recursive C-Program and recurrence relation to find 𝑛𝑡ℎ fibonacci number.