| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
hard
Worst-Case ArrayList Insertion Complexity
< Prev
Next >

What is the worst-case time complexity of a single add operation on an ArrayList that requires the internal array to be resized?

A

Every insertion always takes O(n) time, leading to an overall O(n^2) complexity.

B

Resizing operations are handled in constant time, so insertions remain O(1) regardless of resizing.

C

Insertion in an ArrayList is always O(1) and is not affected by resizing.

D

In the worst-case scenario, an insertion can take O(n) time because a resize may require copying all elements, though the amortized cost remains O(1) per insertion.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy