Big O notation (from mathematical perspective)

Click For Summary
SUMMARY

Big O notation is mathematically defined as "f(n) is O(g(n)) if there exist constants c > 0 and n0 such that for all n ≥ n0, f(n) ≤ c * g(n)." In the discussion, examples illustrate constant time complexity O(1) and linear time complexity O(n). The distinction between O(4n) and O(n) versus n^2 ≠ O(n) highlights that the former functions grow at a rate that can be bounded by a constant multiple, while the latter does not. A clear understanding of these relationships is essential for analyzing algorithm efficiency.

PREREQUISITES
  • Understanding of algorithm complexity and runtime analysis
  • Familiarity with mathematical functions and inequalities
  • Basic knowledge of discrete mathematics
  • Proficiency in programming concepts, particularly loops and variable declarations
NEXT STEPS
  • Study the formal definition of Big O notation in algorithm analysis
  • Learn about different time complexities: O(1), O(n), O(n^2), and their implications
  • Explore examples of proving time complexity using mathematical inequalities
  • Investigate related concepts such as Big Omega and Big Theta notations
USEFUL FOR

Students in discrete mathematics, software developers analyzing algorithm efficiency, and anyone seeking to deepen their understanding of computational complexity theory.

skintight
Messages
3
Reaction score
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
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
 
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).
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K