What is the average complexity of push_back on std::vector?
-
A
Amortised constant time
Correct answer
-
B
Logarithmic in the size
-
C
Linear in the size every time
-
D
Quadratic in the size
Correct answer
A. Amortised constant time
13 views
Explanation
push_back is amortised constant time because the capacity grows geometrically when it runs out.
Reference
Asked in: NTS, PPSC IT, Campus Interviews
Doubts & discussion
Not sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ