3 ms·
result = 0 for each x in L: result += x for each x in M: result -= x (Loops arent nested here but done sequentially) Whats the ballpark? O(2N) you might say
by quadcore 5y ago
result = 0
for each x in L: result += x
for each x in M: result -= x
(Loops arent nested here but done sequentially)
Whats the ballpark? O(2N) you might say. Nah, its like saying that x+1 is O(2), you re not giving me the ballpark here. What matters is how fast it grows when we put in more inputs. We dont care how many operations there is exactly.
It's O(N). Think of it like, whatever are the details, we have traversed one list, the concatenation of L and M. Weve just traversed lists sequentially, its in the ballpark of traversing one (think of it as a big one if you need too) list. O(N).