1

2^n=O(3^n) : This is true or it is false if n>=0 or if n>=1 since 2^n may or not be element of O(3^n) I need a hint to figure the problem

Raphael
  • 72,336
  • 29
  • 179
  • 389
geometry18
  • 21
  • 1
  • 1
    Welcome to Computer Science! What have you tried? Where did you get stuck? We do not want to just hand you the solution; we want you to gain understanding. However, as it is we do not know what your underlying problem is, so we can not begin to help. See here for tips on asking questions about exercise problems. If you are uncertain how to improve your question, why not ask around in [chat]? – Raphael Aug 28 '18 at 18:34
  • The title you have chosen is not well suited to representing your question. Please take some time to improve it; we have collected some advice here. Thank you! – Raphael Aug 28 '18 at 18:34
  • Note that as soon as O is involved, n tends towards infinity (in this context). So those lower bounds on n are irrelevant. – Raphael Aug 28 '18 at 18:35

1 Answers1

4

It is a common misconception that O(g(N)) notation represents a function. It actually represents a set of functions whose asymptotic complexity is bounded by the function g(N) as N approaches infinity. In your example, g(N) = 3^N.

So to ask is 2^n = O(3^n) is mixing apples and oranges, or in this case you are comparing a function with a set of functions. We often write it this way, but it is understood that we are talking about membership in a set of functions, not equality.

The more correct way to state this is:

Is function 2^n contained in the set of functions represented by O(3^n)?

With the question phrased this way, the exact values of n do not enter into it because now you are asking if the function 2^n is a member of the set O(3^n).

The short answer is: yes it is.

But to understand why, you need to understand the formal definition of big-O notation which is:

   f(x) is contained in O(g(x)) 

if and only if for all sufficiently large values of x, the absolute value of f(x) is at most a positive constant multiple of g(x). That is, f(x) = O(g(x)) if and only if there exists a positive real number M and a real number x0 such that

|f(x)| <= Mg(x) for all x >= x0 

So for 2^n and O(3^n), we can set M to 1 and x0 to 1, and we get:

|2^n| <= 3^n for all n >= 1

With n=1, we have 2 <= 3, which is true. With n=2, we have 4 <= 9, which is also true, and informally we can see that 3^n grows faster than 2^n, so we know this relationship holds for all n > 2 as well, and thus:

2^n is contained in O(3^n)

For a more complete description of big-o notation, refer to this excellent post https://cs.stackexchange.com/a/23594/87624 or for something specific to BigO notation, read the Wikipedia article on big-o notation

ScottK
  • 208
  • 3
  • 10
  • The important point is that, AFAIK, in pure CS, O() considered as upper limit, while in practical programming it's considered as exact class so f.e. f(n)=n isn't in O(n^2) class (AFAIR I learned that from the popular "Cracking the Programming Interview" book and it corresponds to my own experience. – Bulat Aug 28 '18 at 07:27
  • @Bulat f(n)=n IS in O(n^2). O() is not the upper limit, it is an asymptotic bound in the limit of n, to within a constant multiple. So for example, f(2n^2) is also in O(n^2), and is f(2n^2 + 1000000), because in both cases as n gets large, there exists an n0 and an M, (in this case 2) such that these functions are bounded by Mg(x) which in this case is 2(n^2). – ScottK Aug 28 '18 at 13:35
  • As I already said, in practical programming it usually considered as both upper and lower limit i.e. exact class. F.e. example if you will say at interview that merge sort is O(n^2), it will be no hire. – Bulat Aug 28 '18 at 13:52
  • @Bulat I have to disagree again, I am a "practical programmer" with 30 years experience in industry. We would never consider O() to be the upper and lower limit. You may be thinking of Big Theta notation, which says that the function is bounded (within a constant multiple) on both upper and lower values, in other words theta(g(x)) means g(x) is a time upper and lower bound (in the limit). – ScottK Aug 28 '18 at 14:05
  • @Balut, I should have clarified that I agree with you that there are many in industry that have this perception of what Big-O notation is, but that does not make it correct. I apologize for not acknowledging your experience. I hope you will help educate them on the correct meaning of these notations if it helps the project succeed. Good luck! – ScottK Aug 28 '18 at 14:46
  • 1
    It's like Pidgin English - people in industry (including me) so rarely need these things, that it's easier to occasionally say "algorithm A has lower bound of O(n)" rather than to remember the correct notation – Bulat Aug 28 '18 at 15:00
  • 1
    @Balut, Absolutely true and I agree. For industry, that short hand is perfectly awesome for a design discussion! The more formal notation and ideas would get in the way of a great discussion on design. – ScottK Aug 28 '18 at 15:21
  • Hi, thanks for your answer! Would you agree that our reference question is enough answer for this question? We prepared it as one of several questions/answers that should solve many frequently asked "beginner" questions. – Raphael Aug 28 '18 at 18:36
  • 1
    @Bulat In practice, O shouldn't factor into a design (without detailed understanding) because it may provide many a red herring. – Raphael Aug 28 '18 at 18:37
  • Hi @Raphael, personally I would want to keep this question around, as my answer references the reference question, and this creates another breadcrumb to find it. I bow to you experience in wisdom of course. (I will be sad to lose the points but I have no wish to clutter up StackExchange if you feel it is redundant). Thanks for asking. – ScottK Aug 28 '18 at 19:13
  • @Raphael In addition, I really like the discussion about work versus academia. It highlights a disconnect between the two communities, that I think discussion expands upon that the other thread doesn't. Just my 2 cents of course, feel free to do what is right. Thanks gain. – ScottK Aug 28 '18 at 19:15
  • @ScottK You link another reference question, one that has less to do with O. (If anything, I'd close this as duplicate; it'd stay around and could still be voted on.) – Raphael Aug 28 '18 at 20:00
  • @ScottK Being a TCSist in software development industry, I don't think there is any disconnect beyond a gap in expertise. Sadly, the average CS graduate has not understood the theory of algorithms well enough to understand its applications and limitations. – Raphael Aug 28 '18 at 20:01
  • @Raphael Yes, depending on the industry, there may or may not be a gap. I have worked in telecom and big data, and in both companies we were experts in complexity, and had tight design limits on our data structure that ensured scalability by insisting on O(1) performance in critical path use cases. – ScottK Aug 28 '18 at 20:30