Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the Time complexity big-oh notation of the following algorithms ? Explai

ID: 3833746 • Letter: W

Question

What is the Time complexity big-oh notation of the following algorithms ? Explain
a.
int function1(int n)
{
int m =5;
for(int i = 0; i<n ; i++)
m += 1 ;

return m ;
}
b.
int function1(int n)
{
int m =5;
for(int i = 0; i<n ; i++)
m += 1 ;

for(int i =0 ;i <5 ;i++)
m +=1;

return m ;
}
c.
int function1(int n)
{
int m =0;
for(int i = 0; i<n ; i++)
{
for (int j = 0; j<n ; j++)
m += 1;
}

for(int i = 0; i<n ; i++)
{
for (int j = 0; j<10 ; j++)
m += 1;
}
return m ;
}
d.
int function1(int n)
{
int m =0;
for(int i = 0; i<n ; i++)
{
for (int j = 0; j < Math.sqrt(n) ; j++)
m += 1;
}
return m ;
}

Explanation / Answer

a) O(n). The loop runs n times.
b) O(n). The loop runs n times.
c) O(n^2). There is a nested loop the first loop runs n times and the second loop runs n times.
d) O(nn). There is a nested loop the first loop runs n times and the second loop runs n times.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote