I have code that is first creating a vector (vector B). My code then loops through a different vector (vector A) in the program and adds that index to the back of Vector B.
My thoughts are that since we are looping through n elements the time complexity will be worse case O(n^2) since we might need to create an entirely new array if vector b gets too big. average time of O(n) since push back usually is constant.
Now for space complexity since we are already creating space to hold n elements, it would be O(N). However, if our vector is too big we might need to create an entirely new one of O(N) size. So would our space be O(2n) which is just O(n) or would it be O(n + m) (m being the size of the new array).
Thanks!