What Are Big O, Big Omega, and Theta Notations?

3.3M views
•
January 15, 2020
by
Gate Smashers
YouTube video player
What Are Big O, Big Omega, and Theta Notations?

TL;DR

Big O, Big Omega, and Theta describe an algorithm’s upper bound, lower bound, and two-sided bound, respectively. They support prior analysis by expressing time complexity without executing the algorithm. For f(n) = 2n^2 + n, the dominant term is n^2, and a Big O proof works with c = 3 for n greater than or equal to 1. Read on for the definitions, proof, and comparison example.

Transcript

Hello friends, welcome to Gate Smashers In this video we are going to discuss about asymptotic notations And this is one of the most important topics of the algorithm Because we discuss asymptotic notations in the syllabus So guys in this video we are going to discuss all the important points from the basics Which will be very beneficial for your ... Read More

Key Insights

  • Asymptotic notation is the mathematical way of representing time complexity. It supports prior analysis, where an algorithm is analyzed without execution, by counting how many times a statement runs (iteration or frequency) or how many times a function calls itself.
  • The purpose of notations is comparison. By representing one algorithm as having a certain time complexity and another as having a different one, the two can be compared directly so the better algorithm can be identified without running either.
  • Big O notation represents the upper bound, also called at most, meaning the maximum time a task will take. Formally f(n) = O(g(n)) holds when f(n) is less than or equal to c.g(n), for a constant c greater than 0 and all n greater than or equal to k.
  • Big O requires the least upper bound, not just any larger function. For 2n^2 + n, the terms n^2, n^3, n^4, n^5, 2^n, and n^n are all valid upper bounds mathematically, but only the closest one, n^2, is chosen.
  • The dominating term decides the complexity class. In 2n^2 + n, n^2 is quadratic and n is linear, and at n = 100 the linear term is 100 while the quadratic term is 10,000, so n^2 dominates for large inputs even though small values of n show little difference.
  • For f(n) = 2n^2 + n written as O(n^2), c = 2 fails because the extra plus n term breaks the inequality, so c = 3 is chosen. Solving 2n^2 + n <= 3n^2 gives n <= 2n^2, then 1 <= n, so the condition holds for all n greater than or equal to 1.
  • Big Omega represents the lower bound, also called at least, and requires the greatest lower bound. For 2n^2 + n, candidates such as n^2, n, log n, and log of log n are all smaller, but the nearest one, n^2, is chosen, with c = 2 and n greater than or equal to 0.
  • Theta notation bounds a function from both sides and represents the average case. For f(n) = 2n^2 + n with g(n) = n^2, c1 = 2 and c2 = 3, so 2n^2 + n is always greater than 2n^2 and always less than 3n^2.
  • Big O is the notation most commonly used in practice because it reports the maximum time, which automatically covers the best case and average case within it. That is also why most complexity results are stated in terms of Big O.
  • Little o differs from Big O by removing equality. Where Big O uses less than or equal to, in little o the equal to part does not apply, which is what separates it from the big notation.

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What are Big O, Big Omega, and Theta notations?

Big O represents an upper bound, or at most; Big Omega represents a lower bound, or at least; and Theta bounds a function from both sides. These asymptotic notations express time complexity mathematically so algorithms can be analyzed and compared without being executed.

Q: What is asymptotic notation in algorithms?

Asymptotic notation is a mathematical way to represent an algorithm’s time complexity. In prior analysis, you count statement executions, iterations, frequencies, or recursive function calls instead of running the algorithm, then use those counts to compare algorithms.

Q: What does Big O notation represent?

Big O represents the upper bound of a function, described as at most or the maximum time a task will take. Formally, f(n) = O(g(n)) when f(n) is less than or equal to c·g(n) for a constant c greater than 0 and all n greater than or equal to k.

Q: How do you prove that 2n^2 + n is O(n^2)?

Start with 2n^2 + n ≤ c·n^2. Choosing c = 3 gives 2n^2 + n ≤ 3n^2, which holds for all n greater than or equal to 1; therefore, 2n^2 + n is O(n^2).

Q: Why is n^2 chosen instead of n^3 or 2^n for the Big O of 2n^2 + n?

Big O uses the least upper bound, meaning the closest suitable upper bound rather than any larger function. Although n^3, n^4, n^5, 2^n, and n^n can also sit above 2n^2 + n, n^2 is the closest listed choice.

Q: Why does n^2 dominate n in 2n^2 + n?

The quadratic term grows faster than the linear term as the input increases. At n = 100, n is 100 while n^2 is 10,000, so n^2 determines the asymptotic complexity for large inputs.

Q: What does Big Omega notation represent?

Big Omega represents the lower bound of a function, described as at least or the minimum time a task will take. For 2n^2 + n, the greatest lower bound is n^2, and c = 2 provides the lower comparison.

Q: How does a linear book search illustrate best, worst, and average cases?

Without indexing or hashing, finding the topic on the first page is the best case, while finding it on the last page after checking all n pages is the worst case. The average case requires moving through roughly half of the pages.

Summary & Key Takeaways

  • Asymptotic notation is the mathematical way of representing time complexity, and it belongs to prior analysis, meaning the algorithm is analyzed without being executed. Instead of running code, you count how many times a statement is executed, called iteration or frequency, or how many times a function calls itself, then express that count with a notation.

  • Big O notation represents the upper bound, also stated as at most, meaning the maximum time a task will take. Writing f(n) = O(g(n)) means f(n) is always less than or equal to c.g(n), where the constant c is greater than 0 and the input n is greater than or equal to k, with k greater than or equal to 0.

  • Big Omega represents the lower bound, also stated as at least, and f(n) = Omega(g(n)) means f(n) is always greater than or equal to c.g(n). Theta bounds the function from both sides at once, requiring f(n) to be greater than c1.g(n) and less than c2.g(n), which represents the average case time complexity.

  • The book search example makes the three cases concrete. With no indexing or hashing and a plain linear search, the best case is finding the topic on the first page, the worst case is finding it on the last page after checking all n pages, and the average case is moving through roughly half the pages.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Gate Smashers 📚