| | |
Time complexity of algorithm
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() | View First Unread |
•
•
Join Date: Sep 2006
Posts: 26
Reputation:
Solved Threads: 0
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
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.
•
•
Join Date: Sep 2006
Posts: 26
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
The outer loop executes log n times. The inner one, n times per each outer loop iteration. Multiplication gives the total # of iterations, n log n.
•
•
Join Date: May 2007
Posts: 1
Reputation:
Solved Threads: 0
Can someone help on this one please?
If I have this:
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?
If I have this:
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?
![]() |
Similar Threads
- calculate time complexity of the algorithm (Computer Science)
- time complexity of algorithm (Computer Science)
- Calculating time complexity (Computer Science)
- Help On Time Complexity Algorithm (Computer Science)
Other Threads in the Computer Science Forum
- Previous Thread: An example of an API?
- Next Thread: How do you for loop into a while loop??
| Thread Tools | Search this Thread |








