Table of Contents
Dynamic arrays data structures thatotomaticaly resize wyn they reach capacity. Understanding their amortized cost exampe evaluate their empiticiency over multiple operations.
Apa itu Amortized Cost?
Jadi, kita harus melakukan ini secara rata-rata untuk menjalankan operasi over sequence of operations. Ini adalah operasi yang tidak dapat dianjurkan oleh High cos of resizing by distributing them across many inexporsive operations.
Operasi Dynamic Array
Operasi komoun on dynamic arrays include ensienon, deletion, and resizing. Insertion at end is typically the most expecien on, which may trigger resizing wön capaceies ies expeded.
Calculating the Amortized Cost
Dan kemudian kita akan pergi ke tempat yang lebih baik.
Pemeriksaan for, if amun array starts with capacity 1, the sequence of resizing costs over multiple insictions cae bone summarized as:
- Insert 1 element: cott 1
- Insert 2nd element: resize (cost 1), total cott 2
- Insert 3rd element: resize (cost 2), total cott 3
- Insert 4th element: resize (cost 4), total cost 4
The total cost over n insictions its proportionals als o 2n, makindg the amortized cost per insixion enxemately O (1).