Big O notation (from mathematical perspective)

In summary, Big-O notation is a mathematical way of defining the relationship between two equations, f(n) and g(n). It states that f(n) is less than or equal to g(n), multiplied by a constant, up to a certain point. If there exists a constant c such that f(n) is less than or equal to c multiplied by g(n), then f(n) is considered to be Big-O of g(n). This notation is used in run-time analysis to determine the efficiency of algorithms and functions.
  • #1
skintight
3
0

Homework Statement



Give a clear and concise mathematical definition for Big-O. ("f(n) is O(g(n)) if...")

Homework Equations





The Attempt at a Solution



I'm in a discrete math class and overall I understand the concept of run-time analysis. For example, if a variable is declared it would be O(1) because it is constant no matter on the data set.

Here is an example:

Code:
int x = 10 // constant run time.

And, here is an example of O(n)

Code:
for (int i = 0; i < n; i++)
{
      print "hello\n"
}

What I don't understand is how to prove this from a mathematical perspective. What screws me up is this wording (yes, all those parenthesis); f(n) is O(g(n))

Is there a way that I can rewrite that statement without the parenthesis, or can someone explain this problem in a different way? I am confident I can solve it but I need to understand it first.

What I think the problem is saying is this.

There are two equations:
- f(n)
- g(n)

Given a problem I need to show the the function / equation f(n) (whatever it is) has a run time of whatever the function / equation g(n) is. Is this correct?

Thanks for any assistance.
 
Last edited:
Physics news on Phys.org
  • #2
You're not supposed to prove anything. You're only supposed to define big-O notation mathematically.

Here's some facts that might help you:

n=O(4n)
4n=O(n)
n^2=/=O(n)

What's the difference between the first two and the third?

So big O means that the first function is less than or equal to the second function up to a constant. There does not exist a constant c such that n^2<=c*n for all n. That's why n^2=/=O(n). Try to formalize this into a definition
 
  • #3
oh, thanks grief. i think i have now solved it using your clear explanation. obviously, f(n) has to be less than or equal to to some constant, Z, multiplied by g(n) given that another constant is less then f(n).
 

1. What is Big O notation and why is it important in computer science?

Big O notation is a mathematical concept used to describe the time complexity of an algorithm. It represents the worst-case scenario for the time it takes for an algorithm to run, and is important in computer science because it allows us to analyze and compare the efficiency of different algorithms.

2. How is Big O notation calculated?

Big O notation is calculated by looking at the growth rate of an algorithm's runtime as the input size increases. It is typically represented as a function of n, the size of the input. The most dominant term in the function is used to determine the Big O notation.

3. What is the difference between O(1) and O(n) time complexity?

O(1) time complexity means that the runtime of an algorithm does not change with the input size. This is considered the most efficient time complexity. O(n) time complexity means that the runtime of an algorithm is directly proportional to the input size. As the input size increases, the runtime also increases.

4. Why is it important to understand the limitations of Big O notation?

While Big O notation is a useful tool for analyzing and comparing algorithms, it has its limitations. It only considers the worst-case scenario and does not take into account factors such as hardware and programming language. It is important to understand these limitations in order to make informed decisions when designing and implementing algorithms.

5. Can an algorithm have multiple Big O notations?

Yes, an algorithm can have different time complexities for different inputs. For example, an algorithm may have an O(1) time complexity for a small input size, but an O(n^2) time complexity for a larger input size. In this case, we would say that the algorithm has a time complexity of O(n^2) as it represents the worst-case scenario.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
911
Back
Top