LearnFrenzy
Sign in Take a free test

Data Structures in Java · Data Structures in Java MCQ · Question 6

Amortized cost of appending to a dynamic array Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

A dynamic array doubles its capacity when full. What is the amortized time per append?

  • A O(n)
  • B O(log n)
  • C O(1) Correct
  • D O(n²)
Correct Answer: Option C

Copies happen at sizes 1, 2, 4, 8 …; their total is under 2n, so n appends cost O(n) in all – O(1) each on average.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links