Mistakamikaze
Mistakamikaze

Reputation: 442

What is the time complexity of Looping through an array, if when I get to my final element, I have to loop through another array just once

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

Answers (1)

Matt
Matt

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

Related Questions