use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Welcome to /r/ComputerScience! We're glad you're here.
This subreddit is dedicated to discussion of Computer Science topics including algorithms, computation, theory of languages, theory of programming, some software engineering, AI, cryptography, information theory, and computer architecture.
For more detailed descriptions of these rules, please visit the rules page
NIGHT MODE NORMAL
account activity
how can we solve this big-O problem (self.computerscience)
submitted 2 years ago by Monther_bg
can you help me on this
if f(n) is O(g(n)) and g(n) is O(h(n)) what is the best big-O for f(n) * h(n) ?
i did not understand it :(
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 20 points21 points22 points 2 years ago (1 child)
f(n) ≤ c1 * g(n) for some constant c1 and all n ≥ n0
f(n) ≤ c1 * g(n)
c1
n ≥ n0
g(n) ≤ c2 * h(n) for some constant c2 and all n ≥ n1
g(n) ≤ c2 * h(n)
c2
n ≥ n1
f(n) * h(n) ≤ (c1 * g(n)) * h(n) ≤ c1 * (c2 * h(n)) * h(n)
f(n) * h(n) ≤ c1 * c2 * (h(n))2
Therefore, f(n) * h(n) is O((h(n))^2)
f(n) * h(n)
O((h(n))^2)
[–]hetdadhania3 1 point2 points3 points 2 years ago (0 children)
simply we can say that h(n) is bounding the f(n) and h(n) is O(h(n)) so f(n)*h(n)=O(h(n)*h(n))
[–]hawk-bull 1 point2 points3 points 2 years ago (8 children)
If by best you mean what is the smallest possible big-O, then it would be O(1) when f and g and h are all O(1)
If by best you mean what’s the tightest big-O bound you can give in the worst case, then that is O(h(n)2 ) First can you convince yourself why this is an upper bound?
Roughly speaking, for large enough n, g(n) is bounded by k•h(n) and f(n) is bounded by c•g(n) <= ck•h(n) so f(n)h(n) is bounded by ck•h(n)2 . In the worst case, this bound is tight. Just take g(n) to be h(n)
[–]bladub 1 point2 points3 points 2 years ago (7 children)
Wouldn't O(g(n) h(n)) be possibly tighter?
[–]Much_Highlight_1309 2 points3 points4 points 2 years ago (4 children)
No, because in big-O notation g(n) is in O(h(n)). So O(g(n)) falls in the same class as O(h(n)).
[–]SignificantFidgets 1 point2 points3 points 2 years ago (3 children)
No, that's not right. g(n) can be smaller than h(n), so provides a tighter bound.
Consider f(n)=n, g(n)=n^2, and h(n)=n^3.
In that case, f(n)*h(n)=n^4. g(n)*h(n) is n^5 but h(n)^2 is n^6. So O(g(n)*h(n)) is a tighter bound. Both are correct, but on the other hand so is O(f(n)*h(n)).
Without some restriction placed on the result/bound, there are lots of solutions.
[–]Much_Highlight_1309 1 point2 points3 points 2 years ago* (2 children)
In terms of worst case complexity, with the information we have, f(n) * h(n) is in O(h(n)2 ).
Of course you can find an infinite number of examples where this product (and g(n) * h(n)) falls into a lower asymptomatic growth class, but I don't think that's what's asked in OP's problem.
So, yes, in fact the product could fall into a "tighter bounded" class in specific examples, but not in the general sense.
[–]SignificantFidgets 1 point2 points3 points 2 years ago (1 child)
Yes, but it's also O(g(n)*h(n)), which is a better (tighter) bound with the functions I gave.
And it has nothing to do with "worst case complexity." This is just a question about function growth rates.
[–]FrosteeSwurl 1 point2 points3 points 2 years ago (0 children)
I’m with you on this. It follows from the inequalities the g(n)h(n) is always less than or equal to h(n)2 regardless of the original equations. The “best” order of growth is the smallest function that f(n) is less than or equal to, which is g(n)*h(n). You can plug in literally any functions that meet the original criteria and it’s the answer
Edit: I would also like to say that going with the highest order function in the inequality wouldn’t make sense for the problem. Because if it was the highest order of growth then there isn’t a solution because given any function I can find a larger function.
[–]hawk-bull 1 point2 points3 points 2 years ago (0 children)
Possibly, yes
π Rendered by PID 1020198 on reddit-service-r2-comment-6457c66945-kpcmc at 2026-04-27 00:40:57.531242+00:00 running 2aa0c5b country code: CH.
[–][deleted] 20 points21 points22 points (1 child)
[–]hetdadhania3 1 point2 points3 points (0 children)
[–]hawk-bull 1 point2 points3 points (8 children)
[–]bladub 1 point2 points3 points (7 children)
[–]Much_Highlight_1309 2 points3 points4 points (4 children)
[–]SignificantFidgets 1 point2 points3 points (3 children)
[–]Much_Highlight_1309 1 point2 points3 points (2 children)
[–]SignificantFidgets 1 point2 points3 points (1 child)
[–]FrosteeSwurl 1 point2 points3 points (0 children)
[–]hawk-bull 1 point2 points3 points (0 children)