In: Computer Science
What is time Complexity each of the following function?
1-
void function(int n)
{
for (int i=n/2; i<=n; i++)
for (int j=1; j<=n/2; j++)
for (int k=1; k<=n; k = k * 2)
print ”Hello”;
}
2-
void function(int n)
{
for (int i=n/2; i<=n; i++)
for (int j=1; j<=n; j = 2 * j)
for (int k=1; k<=n; k = k * 2)
print ”Hello”;
}
3-
void function(int n)
{
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j = j + i)
print ”Hello”;
}
4-
Int n=22^k
for (int i=1; i<=n; i++)
{
J=2
While(j<=n)
{
j=j2
print ”Hello”;
}
}
5=
If n>=2
While(n>1)
{
n=n/2;
print ”Hello”;
}
1-
void function(int n)
{
for (int i=n/2; i<=n; i++)
for (int j=1; j<=n/2; j++)
for (int k=1; k<=n; k = k * 2)
print ”Hello”;
}
ANSWER:n3
---------------------------------------------------------------------------------------------------------------------------
2-
void function(int n)
{
for (int i=n/2; i<=n; i++)
for (int j=1; j<=n; j = 2 * j)
for (int k=1; k<=n; k = k * 2)
print ”Hello”;
}
ANSWER:n3
---------------------------------------------------------------------------------------------------------------------------------------------------
3-
void function(int n)
{
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j = j + i)
print ”Hello”;
}
ANSWER:n2
---------------------------------------------------------------------------------------------------------------------------------------------------
4-
Int n=22^k
for (int i=1; i<=n; i++)
{
J=2
While(j<=n)
{
j=j2
print ”Hello”;
}
}
ANSWER:n2
---------------------------------------------------------------------------------------------------------------------------------------------------
5=
If n>=2
While(n>1)
{
n=n/2;
print ”Hello”;
}
ANSWER:n
---------------------------------------------------------------------------------------------------------------------------------------------------