any tutorial or website to help me...i want to get the time complexity of this algo using summation and big o...i really find it difficult to understan...can you help me please solve step by step
add=0;
for (a=1 to n) do
for b=1 to a*a do
for c=1 to b do
add=add+c;
anyone please help
Last edited by vbcielle; Mar 11th, 2007 at 3:58 am.
I think in this case, addition is based on for loops.
And there are 3 loops in your given algo.
An exmaple of three loops is also present on this thread or of a similar kind of thread.
I suggest you read them first and you will be able to find a solution by yourself.
I think in this case, addition is based on for loops.
And there are 3 loops in your given algo.
An exmaple of three loops is also present on this thread or of a similar kind of thread.
I suggest you read them first and you will be able to find a solution by yourself.
hello yes i read it but it's quite vague can you help me how to do it step by step? i've been searching the web but can't find site that will help a dummy like me
any tutorial or website to help me...i want to get the time complexity of this algo using summation and big o...i really find it difficult to understan...can you help me please solve step by step
add=0;
for (a=1 to n) do
for b=1 to a*a do
for c=1 to b do
add=add+c;
anyone please help
Looks like n^5 to me. The outermost loop executes n times, the next-inner one on the order of a^2, which in the worst case is n^2, and the inner-most to that same n^2 worst-case.
Multiply these out to find the minimum number of executions and they will be on the order of n^5.
Ya , I think the solution to the given program is correct. The outer loop divids the sampling increment by 2. Hence it is log N and the inner loop is straight forward. Its N.
so solution is O(NlogN)
public static boolean find(int [] a, int k) {
for (i = 0; i < a.length; i++) {
for (j = 0; j < a.length; j++) {
if ((a[i] + a[j]) == k) {
return true;
}
}
}
return false;
}
Would the time complexity of this be 2n^2 therefore O(n^2)?
Am I counting it correctly? An if statement condition within the second FOR loop is run n times and the second FOR loop is run n times, therefore 2n and then the first FOR loop runs n times, therefore (2n * n) operations?
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.