•
•
•
•
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
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
•
•
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.)
>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".
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.
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
>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.
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.
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
what if
is O(n) or O(n2) because MyTable.RecordCount is also counts
pascal Syntax (Toggle Plain Text)
MyTable1.First; for i := 1 to MyTable.RecordCount do begin ... end;
is O(n) or O(n2) because MyTable.RecordCount is also counts
•
•
Join Date: Aug 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Computer Science and Software Design Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp blog browsing business software computer dell design developer development erp systems firefox india intel internet it linux media microsoft mmorpg msdn networking news office online open open-source operating programming project management publishing rss science security software software selection source sql sun super system technology evaluation tips vista warez web wiki windows xp
- calculate time complexity of the algorithm (Computer Science and Software Design)
- Help On Time Complexity Algorithm (Computer Science and Software Design)
Other Threads in the Computer Science and Software Design Forum
- Previous Thread: Time complexity of loops
- Next Thread: Is there any way to intercept the print command in browser?



Linear Mode