943,913 Members | Top Members by Rank

Ad:
You are currently viewing page 4 of this multi-page discussion thread; Jump to the first page
Mar 7th, 2007
0

Re: Time complexity of algorithm

Thank you for a quick reply. I have a long program with me. I wonder it will take many days to calculate its complexity.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fahimarif is offline Offline
9 posts
since Mar 2007
Mar 11th, 2007
0

Re: Time complexity of algorithm

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.
Reputation Points: 16
Solved Threads: 0
Light Poster
vbcielle is offline Offline
26 posts
since Sep 2006
Mar 11th, 2007
1

Re: Time complexity of algorithm

Yes, there are tutorials and websites to help you. Try reading the rest of this thread...
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Mar 11th, 2007
0

Re: Time complexity of algorithm

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fahimarif is offline Offline
9 posts
since Mar 2007
Mar 11th, 2007
0

Re: Time complexity of algorithm

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?
Reputation Points: 16
Solved Threads: 0
Light Poster
vbcielle is offline Offline
26 posts
since Sep 2006
Mar 11th, 2007
0

Re: Time complexity of algorithm

Click to Expand / Collapse  Quote originally posted by fahimarif ...
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
Reputation Points: 16
Solved Threads: 0
Light Poster
vbcielle is offline Offline
26 posts
since Sep 2006
Apr 16th, 2007
0

Re: Time complexity of algorithm

Click to Expand / Collapse  Quote originally posted by vbcielle ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slay2k is offline Offline
2 posts
since Apr 2007
Apr 16th, 2007
0

Re: Time complexity of algorithm

Click to Expand / Collapse  Quote originally posted by Gotcha ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slay2k is offline Offline
2 posts
since Apr 2007
Apr 16th, 2007
0

Re: Time complexity of algorithm

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)
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fahimarif is offline Offline
9 posts
since Mar 2007
May 2nd, 2007
0

Re: Time complexity of algorithm

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
monkeyno1 is offline Offline
1 posts
since May 2007

This thread is more than three months old

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.
Message:
Previous Thread in Computer Science Forum Timeline: equivalence relations
Next Thread in Computer Science Forum Timeline: Web Crawler/ Web Spider/ Web Scraper





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC