1

Is there any difference between the two (in the context of graphs)? In my mind I'm thinking that O(n + n) is the same as O(2n) which is just O(n). I can sort of understand that visiting each node more than once is worse than visiting each node just once but I'm pretty sure that would still fall under O(n).

I might be confusing with O(n + m) but I'm pretty sure I've heard of both before.

Neehal
  • 21
  • 2
  • 3
    Does this answer your question? [Which algorithm is faster O(N) or O(2N)?](https://stackoverflow.com/questions/25777714/which-algorithm-is-faster-on-or-o2n) – Michu93 Oct 23 '20 at 07:13

1 Answers1

1

In general it's O(cn) where c is any constant. So in context of asymptotic complexity O(n) is exactly the same as O(2n). When n is huge constant nearly doesn't have impact.

Michu93
  • 5,058
  • 7
  • 47
  • 80