0

So I came upon this time complexity result and I was confused about it, it said that :

O(nlogn) + O(logn) =O(log(n+1))

Why is that the case? Shouldn't the result be O(nlogn)?

blake
  • 27
  • 1
  • 2
    While this question appears to be about Big-O notation, I suspect the answer can be expressed algebraically rather than conceptually. – Greg Burghardt Mar 17 '22 at 16:59
  • @gnat I think that's helpful, but doesn't answer it directly. I think blake is looking for a break down of the problem and solution. I myself am kinda confused how O(log(n+1)) is the answer here since O(nlogn) seems to take the most amount of time and the time complexity should at least be O(nlogn) long. blake, where did you come across this result? – Christian Mar 17 '22 at 17:11
  • @Christian yeah I'm looking for what you said, because I would of assumed the answer would be O(nlogn) as I mentioned in my post but it's somehow isn't, I found this in my lecture notes , but they're in another language (Turkish), so i cant link them unfortunately – blake Mar 17 '22 at 17:24
  • Ahh I see. Well I'm not sure if anyone'll answer your question here, so I'd say try going the route @GregBurghardt said and try to work this out on your own and see if you get the same answer. If you don't get the same answer, then I'd come back to this question or raise another question with your proof of work. – Christian Mar 17 '22 at 17:28
  • 2
    This is definitely wrong for large n. It might be true if you take the limit for n -> 1 instead of n -> inf for example, but that would be a very non-standard usage. Or some stupid usage like g(n) = O(n log n) + O(log n), but also g(n) = O(log(n+1)). – gnasher729 Mar 17 '22 at 17:47
  • infinity + 1 is just infinity, so the `n+1` can't be proper Big-O notation, no? We might say O(n log(n)) + O(log(n)) = O( (n+1) log(n) ), but again n+1 doesn't fit Big-O notation. – Erik Eidt Mar 17 '22 at 17:52
  • If you calculate a few values of n, it's pretty clear that log(n+1) is much too small. It doesn't make sense that adding more to O time makes the total less. I would say it's the answer you give. If it's anything else, it would be (n+1)logn. – JimmyJames Mar 17 '22 at 19:42
  • 4
    *"So I came upon this time complexity result "* - without more information where you got this wrong statement from, I think closing this question with a pointer to sources how to calculate O(n) correctly is the best we can do here. – Doc Brown Mar 17 '22 at 22:28

0 Answers0