I am relatively new to learning Big-O Notation and was hoping someone could shed some light on a question that, while simple, has been nagging me. This question arose in a different context than the one then I will show below, but it addresses the same concern. Let's say that we had an input array of N elements, and a for loop that will loop over these N elements. Within the loop, however, we perform some constant-size array creations of size 2. Also, please disregard the triviality of this operation, it helps simplify the original problem on which I was working.
for (let i = 0; i < array.length; i++) {
const newArray = [array[i], array[i+1]];
// Do some other stuff...
}
I am thinking that the complexity of this operation would be O(2), but we perform this operation N times, resulting in O(2N), or O(N) since we disregard constants. And although we do allocate memory on each loop, it gets cleaned up between each subsequent iteration and then once upon termination of the loop, so the space complexity would remain O(1). Am I on the right track? Thanks so much!!
newArray.