๐Ÿš€ Mastering Asymptotic Notation in Data Structures & Algorithms (Part 3)

Understanding the Mathematics Behind Big-O

“The mathematical definition is not used to calculate Big-O. It is used to prove that your Big-O answer is correct.” ๐Ÿ’ก


๐Ÿ“– Introduction

Congratulations! ๐ŸŽ‰

In Part 1, we learned:

  • What Asymptotic Notation is
  • Why it was invented
  • What T(n) represents

In Part 2, we learned:

  • What f(n) represents
  • Why we ignore constants
  • Why we ignore lower-order terms
  • Why we keep only the dominant term

By now, you already know how to determine the Big-O notation of most algorithms.

For example,

Suppose the running time of an algorithm isT(n)=3n+2T(n)=3n+2

We immediately writeO(n)O(n)O(n)

Similarly,5n2+7n+205n^2+7n+20

becomesO(n2)O(n^2)O(n2)

Everything looks simple.

But suppose a mathematician asks you a question.

“How do you know that 3n + 2 is actually O(n)?”

Can you prove it?

Simply saying

“Because we ignore constants.”

is not a mathematical proof.

Mathematicians need evidence.

That evidence is provided by one of the most famous formulas in Computer Science.0โ‰คT(n)โ‰คcโ‹…f(n)for all nโ‰ฅn0\boxed{0\le T(n)\le c\cdot f(n)\qquad \text{for all } n\ge n_0}

At first glance, this formula looks scary.

It contains symbols like

  • T(n)
  • f(n)
  • c
  • nโ‚€

Most students memorize it without understanding it.

In this article, we are going to understand every single symbol and, more importantly,

why this formula even exists.


๐Ÿค” Why Was This Formula Invented?

Let’s begin with a simple example.

Suppose you analyzed a Java program.

for(int i = 0; i < n; i++)
{
System.out.println(i);
}

After counting every operation,

you obtainedT(n)=3n+2T(n)=3n+2T(n)=3n+2

You also know thatf(n)=nf(n)=nf(n)=n

because n is the dominant term.

Now you confidently say

The algorithm is O(n).

A mathematician asks

How do you know?

You reply

Because my teacher told me to ignore constants.

The mathematician smiles and says

“That is not a proof.”

He wants mathematical evidence.

That is exactly why the definition was invented.

It provides a formal mathematical proof that your answer is correct.


๐Ÿ“Œ Understanding Every Symbol

Let’s read the formula carefully.0โ‰คT(n)โ‰คcโ‹…f(n)for all nโ‰ฅn00\le T(n)\le c\cdot f(n)\qquad\text{for all }n\ge n_0

Instead of trying to understand the whole equation,

let’s understand it one symbol at a time.


Step 1 โ€“ What Does

0โ‰คT(n)0\le T(n)

Mean?

This is actually the easiest part.

It simply says

The running time of an algorithm can never be negative.

Can an algorithm perform

-50 operations?

No.

Can an algorithm take

-10 seconds?

Again,

No.

Running time is always positive (or zero in a trivial case).

Therefore,T(n)โ‰ฅ0T(n)\ge0T(n)โ‰ฅ0

This part exists simply to make the mathematical definition complete.


Step 2 โ€“ Understanding

T(n)โ‰คcโ‹…f(n)T(n)\le c\cdot f(n)

This is the most important part of the definition.

It says

The actual running time of the algorithm must never grow faster than a constant multiple of the comparison function.

Notice something very important.

The formula does not sayT(n)โ‰คf(n)T(n)\le f(n)

Instead,

it saysT(n)โ‰คcโ‹…f(n)T(n)\le c\cdot f(n)

That small constantccc

changes everything.


Step 3 โ€“ Substitute the Values

SupposeT(n)=3n+2T(n)=3n+2T(n)=3n+2

andf(n)=nf(n)=nf(n)=n

Substituting these into the formula gives3n+2โ‰คcโ‹…n3n+2\le c\cdot n3n+2โ‰คcโ‹…n

Now the problem becomes very simple.

We only need to find any positive constant ccc that makes this inequality true.


Step 4 โ€“ What is c?

This is one of the biggest misconceptions among students.

Many students think

There must be one correct value of c.

That is not true.

The definition says

There exists a positive constant c.

It does not say

Find the smallest value of c.

As long as one valid value exists,

the proof is complete.


Let’s Try c = 3

Substitute it.3n+2โ‰ค3n3n+2\le3n

Subtract3n3n

from both sides.

We get2โ‰ค02\le0

False.

Therefore,

c = 3 does not work.


Let’s Try c = 4

Now3n+2โ‰ค4n3n+2\le4n

Subtract3n3n

We obtain2โ‰คn2\le n

This is true whenevernโ‰ฅ2n\ge2

Great!

Therefore,

c = 4 works.


Can c = 5 Work?

Let’s check.3n+2โ‰ค5n3n+2\le5n

Subtract3n3n

We get2โ‰ค2n2\le2n

or1โ‰คn1\le n

Also true.

Therefore,

c = 5 also works.


Can c = 100 Work?

Absolutely.3n+2โ‰ค100n3n+2\le100n

For sufficiently large values ofnn

this is always true.

Therefore,

c = 100 also works.


๐ŸŽฏ Which Value of c is Correct?

Here is the beautiful part.

They are all correct.

The mathematical definition only says

There exists a positive constant c.

It does not ask us to find the smallest one.

This is why

c is called an arbitrary positive constant.


Step 5 โ€“ What is nโ‚€?

Now let’s understand the last part of the formula.for all nโ‰ฅn0\text{for all }n\ge n_0for all nโ‰ฅn0โ€‹

Many beginners wonder

Why don’t we check every value of n?

Let’s test our previous inequality.

Usingc=4c=4

we obtained3n+2โ‰ค4n3n+2\le4n

Now let’s verify it.

n3n + 24nCondition
154โŒ False
288โœ… True
31112โœ… True
41416โœ… True
51720โœ… True

Notice something interesting.

The inequality fails forn=1n=1

Does that mean

Big-O is wrong?

No.

Because Asymptotic Analysis never studies

small values.

Remember Part 1.

We are interested innโ†’โˆžn\rightarrow\infty

Therefore,

we simply choosen0=2n_0=2

and ignore every value smaller than


๐ŸŽฏ Why Do We Ignore Small Values?

Because Asymptotic Analysis studies

the behaviour of an algorithm

when the input becomes extremely large.

Small values are not important.

That is exactly whyn0n_0โ€‹

exists.


๐Ÿค” Why Do We Ignore Constants?

Now we finally understand the real reason.

SupposeT(n)=5n2+10n+20T(n)=5n^2+10n+20

Why don’t we choosef(n)=5n2f(n)=5n^2

Instead,

we choosef(n)=n2f(n)=n^2

Why?

Because the constant

5

can always be absorbed intocc

This is the actual mathematical reason we ignore constants.

Not because a teacher said so.

Not because a textbook told us to.

But because the mathematical definition already allows multiplication by any positive constant c.


๐ŸŽฏ The Biggest Secret of Big-O

Most students think

the formula0โ‰คT(n)โ‰คcโ‹…f(n)0\le T(n)\le c\cdot f(n)

is used to calculate Big-O.

That is not true.

We calculate Big-O by

  • counting operations,
  • obtaining T(n),
  • identifying the dominant term,
  • choosing f(n).

The mathematical definition is used only to prove that our answer is correct.


๐Ÿ“Œ The Entire Process

  1. Write the algorithm.
  2. Count all operations.
  3. Obtain T(n).
  4. Choose the dominant growth f(n).
  5. Determine the Big-O notation.
  6. If someone asks for proof, use

0โ‰คT(n)โ‰คcโ‹…f(n)0\le T(n)\le c\cdot f(n)0โ‰คT(n)โ‰คcโ‹…f(n)

to justify your answer mathematically.


๐ŸŽฏ Key Takeaways

By now, you should understand that:

  • T(n) is the exact running-time function.
  • f(n) is the simplified growth function.
  • c is any positive constant that makes the inequality true.
  • nโ‚€ is the point after which the inequality must always hold.
  • The formula is not used to calculate Big-O.
  • The formula is used to prove that your Big-O classification is mathematically correct.
  • The reason we ignore constants is that they are already accounted for by the constant c in the definition.

๐Ÿ“ Test Your Understanding

Question 1

What does T(n) represent?

A. Dominant term

B. Actual running-time function

C. Upper bound

D. Lower bound

โœ… Answer: B


Question 2

Why do we introduce the constant c?

A. To calculate Big-O

B. To represent the CPU speed

C. To allow a constant multiple of the comparison function

D. To count the number of loops

โœ… Answer: C


Question 3

True or False?

The value of c must be the smallest possible value.

โŒ False


Question 4

True or False?

The formula 0โ‰คT(n)โ‰คcโ‹…f(n)0 \le T(n) \le c \cdot f(n)0โ‰คT(n)โ‰คcโ‹…f(n) is mainly used to prove that a Big-O classification is correct.

โœ… True


๐ŸŽ‰ Final Conclusion

Congratulations! You’ve now reached a level of understanding that many students never achieve.

You no longer have to memorize the Big-O definition. Instead, you understand why it exists, what every symbol means, and how it connects to the process of analyzing algorithms.

The next time you see:0โ‰คT(n)โ‰คcโ‹…f(n)0 \le T(n) \le c \cdot f(n)

you won’t see a complicated mathematical formula.

You’ll see it for what it really is:

A formal mathematical proof that confirms your Big-O answer is correct.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *