Time complexity of algorithm

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply   View First Unread View First Unread

Join Date: Mar 2007
Posts: 9
Reputation: fahimarif is an unknown quantity at this point 
Solved Threads: 1
fahimarif fahimarif is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #31
Mar 7th, 2007
Thank you for a quick reply. I have a long program with me. I wonder it will take many days to calculate its complexity.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 26
Reputation: vbcielle is an unknown quantity at this point 
Solved Threads: 0
vbcielle vbcielle is offline Offline
Light Poster

Re: Time complexity of algorithm

 
0
  #32
Mar 11th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Time complexity of algorithm

 
1
  #33
Mar 11th, 2007
Yes, there are tutorials and websites to help you. Try reading the rest of this thread...
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 9
Reputation: fahimarif is an unknown quantity at this point 
Solved Threads: 1
fahimarif fahimarif is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #34
Mar 11th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 26
Reputation: vbcielle is an unknown quantity at this point 
Solved Threads: 0
vbcielle vbcielle is offline Offline
Light Poster

Re: Time complexity of algorithm

 
0
  #35
Mar 11th, 2007
Originally Posted by Rashakil Fol View Post
Yes, there are tutorials and websites to help you. Try reading the rest of this thread...
i cant find any website can you please direct me?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 26
Reputation: vbcielle is an unknown quantity at this point 
Solved Threads: 0
vbcielle vbcielle is offline Offline
Light Poster

Re: Time complexity of algorithm

 
0
  #36
Mar 11th, 2007
Originally Posted by fahimarif View Post
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 2
Reputation: slay2k is an unknown quantity at this point 
Solved Threads: 0
slay2k slay2k is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #37
Apr 16th, 2007
Originally Posted by vbcielle View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 2
Reputation: slay2k is an unknown quantity at this point 
Solved Threads: 0
slay2k slay2k is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #38
Apr 16th, 2007
Originally Posted by Gotcha View Post
Verifying if anyone could give me a hand solving this excersices:

Instructions:
Find the Big Oh for the times which is excecuted x : = x + 1. You should justify your answer:

I : = N
WHILE I >= 1 DO
BEGIN
FOR J : = 1 TO N DO
X : = X + 1
I = [I/2]
END
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 9
Reputation: fahimarif is an unknown quantity at this point 
Solved Threads: 1
fahimarif fahimarif is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #39
Apr 16th, 2007
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)
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1
Reputation: monkeyno1 is an unknown quantity at this point 
Solved Threads: 0
monkeyno1 monkeyno1 is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #40
May 2nd, 2007
Can someone help on this one please?

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?
Reply With Quote Quick reply to this message  
Reply

Tags
algorithm, algorithms

Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC