User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Computer Science and Software Design section within the Software Development category of DaniWeb, a massive community of 402,053 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,433 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 61725 | Replies: 54
Reply
Join Date: Jun 2007
Posts: 2
Reputation: senior_mustafa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
senior_mustafa senior_mustafa is offline Offline
Newbie Poster

Re: Time complexity of algorithm

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


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

Question Re: Time complexity of algorithm

  #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  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Time complexity of algorithm

  #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".
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Jun 2007
Posts: 2
Reputation: dkandula is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dkandula dkandula is offline Offline
Newbie Poster

Re: Time complexity of algorithm

  #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  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Time complexity of algorithm

  #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.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Jun 2006
Posts: 1
Reputation: jkp is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jkp jkp is offline Offline
Newbie Poster

Re: Time complexity of algorithm

  #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  
Join Date: Aug 2007
Posts: 9
Reputation: brijendramishra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
brijendramishra brijendramishra is offline Offline
Newbie Poster

UML and OOAD

  #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  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Time complexity of algorithm

  #48  
Sep 4th, 2007
UML has a time complexity of O(n^n) while OOAD has a time complexity of O(n!).
Reply With Quote  
Join Date: Aug 2007
Posts: 9
Reputation: brijendramishra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
brijendramishra brijendramishra is offline Offline
Newbie Poster

Re: Time complexity of algorithm

  #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  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: Time complexity of algorithm

  #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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Computer Science and Software Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Computer Science and Software Design Forum

All times are GMT -4. The time now is 11:54 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC