SCT SD 1915016123 Zulfikar Ridlo Mahasin
SCT SD 1915016123 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
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.
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.