0% found this document useful (0 votes)
10 views3 pages

Assignment 1

Uploaded by

Agam Vishwas
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)
10 views3 pages

Assignment 1

Uploaded by

Agam Vishwas
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/ 3

Find the time complexity for question 1) to 7).

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;
}

8) Given the following recursive function, analyze its time complexity


void function(int n) {
if (n > 1) {
printf("*");
function(n / 2);
function(n / 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy