Reputation: 442
For an array A [0, 1 ... N-1]. I understand that looping through this will take O(n) time. But what if, as I am looping, when I get to N-1, I have to loop through another array B [0, 1 ... N-1]?
My more specific question, is that when I get to N-1, I have to copy the elements of array A into array B and so I was wondering what the time complexity of this is.
Thank you!
Upvotes: 1
Views: 1768
Reputation: 2213
It’s essentially the same as just having two for loops in sequence. The overall complexity is just O(n), because you’re not running the second for loop for each element of the first.
Upvotes: 3