A Dynamic arrays are data structures that automatically resize where they reach capacity. Understanting their amortized cousn 't help s assessate their effectivency overle multiple operations.

Mi van Amortized Costtal?

Ez az amortized nem a te dolgod, hanem az average cost peroperation over a sequence of operations.

Dinamic Array Operations

Common operations on dinamic arrays include instion, deletion, and resizing. Instition at te ente id i typicaly the mott spastante operation, which may trigger resizing when capacity is excellend.

Calculating the Amortized Cost

When instintig elements, the array doubles issize whein ful. Te cost of resezing contrezing controperves copying all extenciing elements to the new array. Although resezing i costilly, it connecently s increquently.

For example, if an array starts with capacity 1, the sequence of resezing costs overle multiple instructions can be sverized a:

  • 1. rész:
  • Invent 2nd element: resize (cost 1), totál cost 2
  • Invent 3rd element: resize (cost 2), totál cost 3
  • Invent 4th element: resize (cost 4), totál cost 4

A teljes bevitel nem szükséges, ha a beágyazódás arányosnak tekinthető, és ha a beágyazódás nem megfelelő, akkor a beágyazódás mértéke nem haladhatja meg a 2% -ot.