Question
Time complexity problem. What's the theta running time for question below? Note that the theta running time for sample below is: So how do I
Time complexity problem. What's the theta running time for question below?
Note that the theta running time for sample below is:
So how do I do question above? There are 4 inner for loops within the main for loop, and amongst those 4 inner loops, I can find the largest term of n, then times the outermost loop running time (n), -> n*n = n^2, but what I concern about is the 1st inner for loop which the running time is basd on "i". What if I change the question to something like this:
for( i = 1; i
for( j = 0; j
sum++;
}
for(j = 0; j
sum++;
}
}
amongst those inner, i know the largest execute time will be n time. Hence big O(nlogn).
But what about theta(n) in this question? How to find theta(n)? The upper bound will be nlogn, what is the lower bound?
My guess answer will be theta(n), I find out the largest term of inner for loop compare with the others, then check if the lower bounds of that inner for loop with the outermost loop, hence my strategy to solve this will be simplify aboved question to :
for( i = 1; i
for( j = 0; j
sum++;
}
}
Since the other inner loop is execute less than this inner loop, this inner loop hold the upperbound, so I just remove it the (logn inner loop) and simply to this. And check what's the lower bound for it.
I found out that this is theta(n),
hence, the answer is theta(n)?
I feel that I'm not consistent with the answer, please correct me if my thought/step to solve is wrong.
Thank you.
Best Regards
for (i-1 ; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started