Time complexity of algorithm

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

Join Date: Jun 2007
Posts: 2
Reputation: senior_mustafa is an unknown quantity at this point 
Solved Threads: 0
senior_mustafa senior_mustafa is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #41
Jun 4th, 2007
Please Help me
how to Know beginning to this branch
please HELP!!!!!!!!!!!


Books , WebSites ,Tutorial
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: dkandula is an unknown quantity at this point 
Solved Threads: 0
dkandula dkandula is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #42
Jun 16th, 2007
Hey
Thanks for the clear explanation. I have a question here whose answer will clarify many things to me.

You say the complexity of this program is O(n). Can I say that it is Theta(n). I dont see the clear distinction when I need to use O, Omega or Theta.

I understand that given two functions O represents one function (actually O is a set with many functions) less than or equal to, while Omega represents greater than or equal to and Theta represents equal. I also have the information that worst case is denoted by O and best case by Omega. I hope you understand my question.

To reiterate it when will I use O, Omega and Theta when it comes to calculating complexity. I know how to come with the "expression". I need to know which symbol to prefix it with.

Regards
Dheeraj

Originally Posted by Rashakil Fol View Post
Count the total number of fundamental operations the algorithm performs, relative to some value N. For example, this function..
int factorial(int n) {
    int ret = 1;
    while (n != 0) {
        ret *= n;
        -- n;
    }
    return ret;
}

The function sets the value of ret to 1. This is one operation.

Then this function tests the condition of the while loop exactly 1 + n times. It runs the body of the while loop exactly n times. The body of the while loop performs exactly 2 fundamental operations: 'multiply ret by n', and 'decrement n'. The condition has one fundamental operation, comparison. Calling the function counts as a fundamental operation, too.

So we have the total number of fundamental operations being
1 + 1 + (1 + n) + 2 * n. (The sum is composed of the operations for calling the function, setting ret = 1, performing a total of 1 + n tests in the condition of the while loop, and a total of 2 * n operations in the body of the while loop.)

This simplifies to 3 + 3 * n fundamental operations, which is O(n).

(What do I mean by 'fundamental operation'? Any operation that takes an amount of time that is bounded by a constant.)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Time complexity of algorithm

 
0
  #43
Jun 16th, 2007
>You say the complexity of this program is O(n). Can I say that it is Theta(n).
Yes. If you calculate the O and Omega and they turn out to be the same, you have a tight bound and can use Theta.

>I dont see the clear distinction when I need to use O, Omega or Theta.
You use O when you want to say "The complexity won't be any greater". You use Omega when you want to say "The complexity won't be any less". And you use Theta when you want to say "The complexity will always be the same".
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: dkandula is an unknown quantity at this point 
Solved Threads: 0
dkandula dkandula is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #44
Jun 16th, 2007
Hi
Thanks for the reply. So when you say calculate Theta and O do you mean that based on the definition of theta and O we need to find constants which satisfies the conditions.

But for an algorithm how is this done. I think we can calculate just the running time right. How can we calculate two different functions for an algorithm. I am not clear on that.
Say for example that an algorithm runs in 3*n*n +1 steps. From this how do you conclude it is O or theta.

This is my confusion.

Regards
Dheeraj
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,813
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Time complexity of algorithm

 
0
  #45
Jun 16th, 2007
>How can we calculate two different functions for an algorithm. I am not clear on that.
Typically the best, average, and worst cases for an algorithm are calculated differently. So you could have three different functions based on those.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1
Reputation: jkp is an unknown quantity at this point 
Solved Threads: 0
jkp jkp is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #46
Aug 23rd, 2007
what if
  1. MyTable1.First;
  2. for i := 1 to MyTable.RecordCount do
  3. begin
  4. ...
  5. end;

is O(n) or O(n2) because MyTable.RecordCount is also counts
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: brijendramishra is an unknown quantity at this point 
Solved Threads: 0
brijendramishra brijendramishra is offline Offline
Newbie Poster

UML and OOAD

 
0
  #47
Sep 4th, 2007
Dear All ,
Kindly Tell me what is the relation between UML and OOAD and what is the difference between them.
Thanks and Regrads,
brijendra Mishra
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
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
  #48
Sep 4th, 2007
UML has a time complexity of O(n^n) while OOAD has a time complexity of O(n!).
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: brijendramishra is an unknown quantity at this point 
Solved Threads: 0
brijendramishra brijendramishra is offline Offline
Newbie Poster

Re: Time complexity of algorithm

 
0
  #49
Sep 18th, 2007
How could you say that UML has time complexity of O(n2) and OOAD (n!).What is the relation? I dont know much on this topic,but what kind of answer is this.
If you are not in a mood to give correct answer then why bother giving at all.
I am not as knowledgeable as you are but ,it is no reason why you should make fun of someone's query.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
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

 
2
  #50
Sep 19th, 2007
Sorry, I assumed that since you were posting a software design question in a thread about time complexity, it was some kind of joke, so I played along.
All my posts may be redistributed under the GNU Free Documentation License.
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



Tag cloud for algorithm, algorithms
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC