| | |
Time complexity of algorithm
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
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".
New members chased away this month: 3
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
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
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
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:
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.
![]() |
Similar Threads
- calculate time complexity of the algorithm (Computer Science)
- time complexity of algorithm (Computer Science)
- Calculating time complexity (Computer Science)
- Help On Time Complexity Algorithm (Computer Science)
Other Threads in the Computer Science Forum
- Previous Thread: Breakthrough heralds new era of cognitive computing
- Next Thread: Help me figure out what drivers do..
| Thread Tools | Search this Thread |
Tag cloud for algorithm, algorithms







