Anda di halaman 1dari 8

Student Name : Zulfikar Ridlo Mahasin

Student ID : 1915016123
Department : Prodi Teknik Informatika Total Marks
Course Name : Data Structure
Date of Task : Friday, August 28, 2020
Time : Maximum by September 9, 2020
Submit to : Will be notified in the MOLS or group

30

4.3 Amortized Cost


The append() operation of the list structure introduces a special case in algorithm
analysis. The time required depends on the available capacity of the underlying array used to
implement the list. If there are available slots, a value can be appended to the list in constant
time. If the array has to be expanded to make room for the new value, however, the append
operation takes linear time. When the array is expanded, extra capacity is added that can be
used to add more items without having to immediately expand the array. Thus, the number of
times the append() operation actually requires linear time in a sequence of n operations
depends on the strategy used to expand the underlying array. Consider the problem in which a
sequence of n append operations are performed on an initially empty list, where n is a power
of 2.
Terjemahan
4.3 Biaya Diamortisasi
Operasi append () dari struktur daftar memperkenalkan kasus khusus dalam analisis
algoritma. Waktu yang diperlukan bergantung pada kapasitas yang tersedia dari array dasar
yang digunakan untuk mengimplementasikan daftar. Jika ada slot yang tersedia, sebuah nilai
dapat ditambahkan ke daftar dalam waktu yang konstan. Jika array harus diperluas untuk
memberi ruang untuk nilai baru, bagaimanapun, operasi penambahan membutuhkan waktu
linier. Saat array diperluas, kapasitas ekstra ditambahkan yang dapat digunakan untuk
menambahkan lebih banyak item tanpa harus segera memperluas array. Jadi, berapa kali
operasi append () benar-benar membutuhkan waktu linier dalam urutan n operasi bergantung
pada strategi yang digunakan untuk memperluas array yang mendasarinya. Pertimbangkan
masalah di mana urutan n operasi penambahan dilakukan pada daftar yang awalnya kosong,
di mana n adalah pangkat 2.

L = list()
for i in range( 1, n+1 ) :
L.append( i )

Suppose the array is doubled in capacity each time it has to be expanded and assume
the size of the underlying array for an empty list has the capacity for a single item. We can
tally or compute the total running time for this problem by considering the time required for
each individual append operation. This approach is known as the aggregate method since it
computes the total from the individual operations.
Terjemahan
Misalkan kapasitas array dua kali lipat setiap kali harus diperluas dan mengasumsikan
ukuran array yang mendasari untuk daftar kosong memiliki kapasitas untuk satu item. Kami
dapat menghitung atau menghitung waktu berjalan total untuk masalah ini dengan
mempertimbangkan waktu yang diperlukan untuk setiap operasi penambahan individu.
Pendekatan ini dikenal sebagai metode agregat karena menghitung total dari operasi
individu.

Table 4.5: Using the aggregate method to compute the total run time for a sequence of 16
append operations.
Table 4.5 illustrates the aggregate method when applied to a sequence of 16 append
operations. si represents the time required to physically store the I th value when there is an
available slot in the array or immediately after the array has been expanded. Storing an item
into an array element is a constant time operation. ei represents the time required to expand
the array when it does not contain available capacity to store the item. Based on our
assumptions related to the size of the array, an expansion only occurs when i − 1 is a power
of 2 and the time incurred is based on the current size of the array (i − 1). While every append
operation entails a storage cost, relatively few require an expansion cost. Note that as the size
of n increases, the distance between append operations requiring an expansion also increases.
Terjemahan
Tabel 4.5 mengilustrasikan metode agregat ketika diterapkan pada urutan 16 operasi
penambahan. si mewakili waktu yang diperlukan untuk secara fisik menyimpan nilai ith
ketika ada slot yang tersedia dalam array atau segera setelah larik diperluas. Menyimpan item
ke dalam elemen array adalah operasi waktu yang konstan. ei merepresentasikan waktu yang
dibutuhkan untuk memperluas array ketika tidak ada kapasitas yang tersedia untuk
menyimpan item. Berdasarkan asumsi kami terkait ukuran array, ekspansi hanya terjadi jika i
- 1 adalah pangkat 2 dan waktu yang dikeluarkan didasarkan pada ukuran array saat ini (i - 1).
Meskipun setiap operasi append memerlukan biaya penyimpanan, relatif sedikit yang
memerlukan biaya perluasan. Perhatikan bahwa dengan bertambahnya ukuran n, jarak antara
operasi append yang membutuhkan perluasan juga meningkat.

Based on the tabulated results in Table 4.5, the total time required to perform a
sequence of 16 append operations on an initially empty list is 31, or just under 2n. This
results from a total storage cost (si) of 16 and a total expansion cost (ei) of 15. It can be
shown that for any n, the sum of the storage and expansion costs, si + ei , will never be more
than T(n) = 2n. Since there are relatively few expansion operations, the expansion cost can be
distributed across the sequence of operations, resulting in an amortized cost of T(n) = 2n/n or
O(1) for the append operation.
Terjemahan
Berdasarkan hasil tabulasi pada Tabel 4.5, total waktu yang dibutuhkan untuk
melakukan urutan 16 operasi penambahan pada daftar yang awalnya kosong adalah 31, atau
sedikit di bawah 2n. Ini dihasilkan dari total biaya penyimpanan (si) 16 dan total biaya
ekspansi (ei) 15. Dapat ditunjukkan bahwa untuk n berapa pun, jumlah biaya penyimpanan
dan perluasan, si + ei, tidak akan pernah lebih dari T (n) = 2n. Karena jumlahnya relatif
sedikit operasi ekspansi, biaya ekspansi dapat didistribusikan ke seluruh urutan operasi,
menghasilkan biaya diamortisasi T (n) = 2n / n atau O (1) untuk operasi tambahan.

Amortized analysis is the process of computing the time-complexity for a sequence of


operations by computing the average cost over the entire sequence. For this technique to be
applied, the cost per operation must be known and it must vary in which many of the
operations in the sequence contribute little cost and only a few operations contribute a high
cost to the overall time. This is exactly the case with the append() method. In a long sequence
of append operations, only a few instances require O(n), while many of them are O(1). The
amortized cost can only be used for a long sequence of append operations. If an algorithm
used a single append operation, the cost for that one operation is still O(n) in the worst case
since we do not know if that’s the instance that causes the underlying array to be expanded.
Terjemahan
Analisis diamortisasi adalah proses menghitung kompleksitas waktu untuk suatu
urutan operasi dengan menghitung biaya rata-rata di seluruh urutan. Agar teknik ini dapat
diterapkan, biaya per operasi harus diketahui dan harus bervariasi di mana banyak operasi
dalam urutan tersebut menyumbang sedikit biaya dan hanya sedikit operasi yang
menyumbang biaya tinggi untuk keseluruhan waktu. Ini persis terjadi dengan metode append
(). Dalam urutan operasi penambahan yang panjang, hanya beberapa instance yang
memerlukan O (n), sementara banyak di antaranya adalah O (1). Biaya perolehan
diamortisasi hanya dapat digunakan untuk rangkaian operasi tambahan yang panjang. Jika
algoritme menggunakan operasi penambahan tunggal, biaya untuk satu operasi tersebut tetap
O (n) dalam kasus terburuk karena kami tidak tahu apakah itu adalah instance yang
menyebabkan larik yang mendasari diperluas.

CAUTION : Amortized Cost Is Not Average Case Time. Do not confuse amortized cost with
that of average case time. In average case analysis, the evaluation is done by computing an
average over all possible inputs and sometimes requires the use of statistics. Amortized
analysis computes an average cost over a sequence of operations in which many of those
operations are “cheap” and relatively few are “expensive” in terms of contributing to the
overall time.
Terjemahan
PERHATIAN: Biaya Amortisasi Bukan Rata-Rata Kasus Waktu. Jangan bingung antara
biaya perolehan diamortisasi dengan rata-rata waktu kasus. Dalam analisis kasus rata-rata,
evaluasi dilakukan dengan menghitung rata-rata dari semua masukan yang mungkin dan
terkadang memerlukan penggunaan statistik. Analisis diamortisasi menghitung biaya rata-rata
selama rangkaian operasi di mana banyak dari operasi tersebut "murah" dan relatif sedikit
yang "mahal" dalam hal berkontribusi pada keseluruhan waktu.
4.4 Evaluating the Set ADT
We can use complexity analysis to determine the efficiency of the Set ADT
operations as implemented in Section 3.1. For convenience, the relevant portions of that
implementation are shown again in Listing 4.1 on the next page. The evaluation is quite
simple since the ADT was implemented using the list and we just evaluated the methods for
that structure. Table 4.6 provides a summary of the worst case time-complexities for those
operations implemented earlier in the text.
Terjemahan
4.4 Mengevaluasi set ADT
Kita dapat menggunakan analisis kompleksitas untuk menentukan efisiensi operasi
Set ADT seperti yang diterapkan di Bagian 3.1. Untuk kenyamanan, bagian-bagian yang
relevan dari implementasi itu ditampilkan lagi pada Listing 4.1 di halaman berikutnya.
Evaluasi cukup sederhana karena ADT diimplementasikan menggunakan daftar dan kami
hanya mengevaluasi metode untuk struktur tersebut. Tabel 4.6 memberikan ringkasan
kompleksitas waktu kasus terburuk untuk operasi yang diterapkan sebelumnya dalam teks.

Table 4.6: Time-complexities for the Set ADT implementation using an unsorted list.

Simple Operations
Evaluating the constructor and length operation is straightforward as they simply call
the corresponding list operation. The contains method, which determines if an element is
contained in the set, uses the in operator to perform a linear search over the elements stored in
the underlying list. The search operation, which requires O(n) time, will be presented in the
next section and we postpone its analysis until that time. The add() method also requires O(n)
time in the worst case since it uses the in operator to determine if the element is unique and
the append() method to add the unique item to the underlying list, both of which require
linear time in the worst case.
Terjemahan
Operasi Sederhana
Mengevaluasi konstruktor dan operasi panjang sangatlah mudah karena mereka hanya
memanggil operasi daftar yang sesuai. Metode __contains__, yang menentukan apakah
sebuah elemen dimuat dalam set, menggunakan operator in untuk melakukan pencarian linier
atas elemen yang disimpan dalam daftar yang mendasarinya. Operasi pencarian, yang
membutuhkan O (n) waktu, akan disajikan di bagian berikutnya dan kami menunda
analisisnya hingga saat itu. Metode add () juga memerlukan waktu O (n) dalam kasus
terburuk karena menggunakan operator in untuk menentukan apakah elemen itu unik dan
metode append () untuk menambahkan item unik ke daftar pokok, keduanya memerlukan
linier waktu dalam kasus terburuk.

Operations of Two Sets


The remaining methods of the Set class involve the use of two sets, which we label A and B,
where A is the self set and B is the argument passed to the given method. To simplify the
analysis, we assume each set contains n elements. A more complete analysis would involve
the use of two variables, one for the size of each set. But the analysis of this more specific
case is sufficient for our purposes.
Terjemahan
Operasi Dua Set
Metode yang tersisa dari kelas Set melibatkan penggunaan dua set, yang kita beri
label A dan B, di mana A adalah himpunan sendiri dan B adalah argumen yang diteruskan ke
metode yang diberikan. Untuk menyederhanakan analisis, kami menganggap setiap set berisi
n elemen. Analisis yang lebih lengkap akan melibatkan penggunaan dua variabel, satu untuk
ukuran setiap set. Tetapi analisis kasus yang lebih spesifik ini sudah cukup untuk tujuan kita.
The isSubsetOf() method determines if A is a subset of B. It iterates over the n
elements of set A, during which the in operator is used to determine if the given element is a
member of set B. Since there are n repetitions of the loop and each use of the in operator
requires O(n) time, the isSubsetOf() method has a quadratic run time of O(n2). The set
equality operation is also O(n2) since it calls isSubsetOf() after determining the two sets are
of equal size.
Terjemahan
Metode isSubsetOf () menentukan apakah A adalah himpunan bagian dari B. Metode ini
mengulangi n elemen himpunan A, di mana operator in digunakan untuk menentukan apakah
elemen yang diberikan adalah anggota himpunan B.Karena ada n pengulangan dari loop dan
setiap penggunaan operator dalam memerlukan waktu O (n), metode isSubsetOf () memiliki
waktu berjalan kuadratik O (n2). Operasi kesetaraan himpunan juga O (n2) karena
memanggil isSubsetOf () setelah menentukan bahwa kedua himpunan berukuran sama.
Set Union Operation
The set union() operation creates a new set, C, that contains all of the unique elements
from both sets A and B. It requires three steps. The first step creates the new set C, which can
be done in constant time. The second step fills set C with the elements from set A, which
requires O(n) time since the extend() list method is used to add the elements to C. The last
step iterates over the elements of set B during which the in operator is used to determine if
the given element is a member of set A. If the element is not a member of set A, it’s added to
set C by applying the append() list method. We know from earlier the linear search performed
by the in operator requires O(n) time and we can use the O(1)amortized cost of the append()
method since it is applied in sequence. Given thatthe loop is performed n times and each
iteration requires n + 1 time, this steprequires O(n2) time. Combining the times for the three
steps yields a worst casetime of O(n2).
Terjemahan
Mengatur Operasi Persatuan
Operasi himpunan union () membuat himpunan baru, C, yang berisi semua elemen
unik dari himpunan A dan B. Ini membutuhkan tiga langkah. Langkah pertama membuat
himpunan C baru, yang dapat dilakukan dalam waktu yang konstan. Langkah kedua mengisi
himpunan C dengan elemen dari himpunan A, yang membutuhkan waktu O (n) karena
metode daftar extended () digunakan untuk menambahkan elemen ke C. Langkah terakhir
mengulangi elemen dari himpunan B selama in operator digunakan untuk menentukan apakah
elemen yang diberikan adalah anggota dari himpunan A. Jika elemen tersebut bukan anggota
dari himpunan A, itu ditambahkan ke himpunan C dengan menerapkan metode daftar append
(). Kita tahu dari sebelumnya bahwa pencarian linier yang dilakukan oleh operator in
membutuhkan waktu O (n) dan kita dapat menggunakan biaya diamortisasi O (1) dari metode
append () karena diterapkan secara berurutan. Mengingat bahwa loop dilakukan n kali dan
setiap iterasi membutuhkan n + 1 kali, langkah ini membutuhkan waktu O (n2).
Menggabungkan waktu untuk tiga langkah menghasilkan waktu kasus terburuk O (n2).

Anda mungkin juga menyukai