Question discussion

A dynamic array doubles its capacity whenever it becomes full. The amortised cost of one append operation is

2152Medium DSSSB TGT Computer Science 0 replies 1 views
0

A dynamic array doubles its capacity whenever it becomes full. The amortised cost of one append operation is

  • AO(n log n)
  • BO(log n)
  • CO(n)
  • DO(1)
Correct answer: D

Explanation

Copying happens at sizes 1, 2, 4, 8, ... so n appends cost about 2n element copies in total, i.e. O(1) per append on average.

Discussion 0

Nobody has replied yet. Start the discussion!