Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Algorithm complexity Lesson 4 CSG3F3.

Presentasi serupa


Presentasi berjudul: "Algorithm complexity Lesson 4 CSG3F3."— Transcript presentasi:

1 Algorithm complexity Lesson 4 CSG3F3

2 Fundamentals of Algorithmic Problem Solving
Understand the Problem Decide on : Computational means, exact vs approximate solving, data structures, algorithms design techniques Design algorithm Prove corectness Analyze the algorithm Code the algorithm RMB/CSG3F3

3 Important Problem Types
Sorting To rearrange the items of given list in ascending/descending order Stable sorting algorithm and Not Stable sorting algorithm RMB/CSG3F3

4 Important Problem Types
Searching Deals with finding a given value, called a search key, in a given set No single algorithm that fits all situations best Sequencial search, binary search RMB/CSG3F3

5 Important Problem Types
String Processing String : a sequence of characters (Levitin) Particular problem : searching for a given word in a text → string matching RMB/CSG3F3

6 Important Problem Types
Graph Problems Graph : a collection of point (vertex), some of which are connected by line segments (edge) For modelling communication network, event schedulling, games, topsort, TSP, graph-coloring. RMB/CSG3F3

7 Important Problem Types
Combinatorial Problems Problem ask to find a combinatorial object Combinatorial objects typically grows extremely fast with problem’s size There no known algorithms for solving most such problems in acceptable amount of time exception : shortest-path problem (diantaranya) Contoh : graph coloring problem, traveling salesman problem, knapsack problems, dll RMB/CSG3F3

8 Sorting To rearrange the items of given list in ascending/descending order Stable sorting algorithm and Not Stable sorting algorithm RMB/CSG3F3

9 Important Problem Types
Searching Deals with finding a given value, called a search key, in a given set No single algorithm that fits all situations best Sequencial search, binary search RMB/CSG3F3

10 Important Problem Types
String Processing String : a sequence of characters (Levitin) Particular problem : searching for a given word in a text → string matching RMB/CSG3F3

11 Important Problem Types
Graph Problems Graph : a collection of point (vertex), some of which are connected by line segments (edge) For modelling communication network, event schedulling, games, topsort, TSP, graph-coloring. RMB/CSG3F3

12 Important Problem Types
Combinatorial Problems Problem ask to find a combinatorial object Combinatorial objects typically grows extremely fast with problem’s size There no known algorithms for solving most such problems in acceptable amount of time exception : shortest-path problem (diantaranya) Contoh : graph coloring problem, traveling salesman problem, knapsack problems, dll RMB/CSG3F3

13 Important Problem Types
Geometric Problems Geometric algorithms deal with geometric objects such as points, lines and polygons. Applications : computer graphics, robotics, dsb Classic problems of computational geometry: The closest pair problem and convex hull problem RMB/CSG3F3

14 Important Problem Types
Numerical Problems Problems that involve mathematical objects of continuous nature Contoh : solving equations and systems of equations, computing definite integrals, evaluating functions, dsb Majority can be solved only approximately Application : information storage, information retreval, transportation through networks, dsb RMB/CSG3F3

15 Analisis Algoritma Algoritma tidak cukup hanya benar saja (correctness), tetapi juga harus mangkus (efisien) RMB/CSG3F3

16 Tujuan Analisis Algoritma
Mengukur efisiensi algoritma dari segi waktu/ruang memori Membanding-bandingkan dua/lebih algoritma untuk masalah yang sama. RMB/CSG3F3

17 Ukuran input (input’s size)
Hampir seluruh algoritma memiliki waktu eksekusi lebih lama jika mendapat input yang berukuran besar, contoh Pengurutan array yang berukuran besar Perkalian matriks yang berukuran besar RMB/CSG3F3

18 Penentuan ukuran input
Penentuan parameter n yang menunjukkan ukuran input sebuah algoritma Sorting, searching, the smallest element  size of the list Polynomial p(x)=anxn+…+a0  polynomial’s degree/number of its coefficients Product of two n -by-n matrices  matrix order n / the number of elements being mulltiplied RMB/CSG3F3

19 Penentuan ukuran input
Apa ukuran input untuk a spell-checking algorithm ? checking whether a given integer n is a prime ? RMB/CSG3F3

20 Satuan ukuran kompleksitas waktu
Operasi dasar (Basic operation ) The most important operation of the algorithm The most time-consuming operation in the algorithm’s innermost loop Contoh: sorting algorithm, matrix multiplication, polynomial evaluation. RMB/CSG3F3

21 Pengukuran efisiensi waktu
Counting the number of times the algorithm’s basic operation is executed on input of size n RMB/CSG3F3

22 Ilustrasi Efisiensi Algoritma
Algorithm: Insertion sort  c1n2, Merge sort  c2 n log n ; c1 < c2 Hardware: Kecepatan komputer A  one billion instructions per second Kecepatan komputer B  ten million instructions per second RMB/CSG3F3

23 Jika c1= 2 dan c2= 50 dan komputer A untuk eksekusi insertion sort dan komputer B untuk merge sort.
Berapakah waktu yang dibutuhkan komputer A dan B (second) untuk mengurutkan bilangan sebanyak 1 juta (n  one million numbers) ? RMB/CSG3F3

24 Mengapa kita memerlukan algoritma yang mangkus
Mengapa kita memerlukan algoritma yang mangkus? Lihat grafik di bawah ini. RMB/CSG3F3

25 Kompleksitas waktu, T(n), diukur dari jumlah tahapan komputasi yang dibutuhkan untuk menjalankan algoritma sebagai fungsi dari ukuran masukan n. RMB/CSG3F3

26 Kompleksitas Waktu Dalam praktek, kompleksitas waktu dihitung berdasarkan jumlah operasi dasar yang mendasari suatu algoritma Contoh 1. Tinjau algoritma untuk mencari elemen terbesar dalam larik yang berukuran n elemen. RMB/CSG3F3

27 Contoh 1. Algoritma untuk mencari elemen terbesar di dalam sebuah larik (array) yang berukuran n elemen. procedure CariElemenTerbesar(input a1, a2, ..., an : integer, output maks : integer) { Mencari elemen terbesar dari sekumpulan elemen larik integer a1, a2, ..., an. Elemen terbesar akan disimpan di dalam maks. Masukan: a1, a2, ..., an Keluaran: maks (nilai terbesar) } Deklarasi k : integer Algoritma maksa1 k2 while k  n do if ak > maks then maksak endif kk+1 endwhile { k > n } RMB/CSG3F3

28 Kompleksitas waktu CariElemenTerbesar : T(n) = n – 1.
Kompleksitas waktu algoritma dihitung berdasarkan jumlah operasi perbandingan elemen larik (A[i] > maks). Kompleksitas waktu CariElemenTerbesar : T(n) = n – 1. RMB/CSG3F3

29 Contoh 2. Algoritma pengurutan seleksi (selection sort).
procedure Urut(input/output a1, a2, ..., an : integer) Deklarasi i, j, imaks, temp : integer Algoritma for in downto 2 do { pass sebanyak n – 1 kali } imaks1 for j2 to i do if aj > aimaks then imaksj endif endfor { pertukarkan aimaks dengan ai } tempai aiaimaks aimakstemp RMB/CSG3F3

30 RMB/CSG3F3

31 RMB/CSG3F3

32 RMB/CSG3F3

33 Contoh 3. Algoritma sequential search.
procedure PencarianBeruntun(input a1, a2, ..., an : integer, x : integer,output idx : integer) Deklarasi k : integer ketemu : boolean { bernilai true jika x ditemukan atau false jika x tidak ditemukan } Algoritma: k1 ketemu  false while (k  n) and (not ketemu) do if ak = x then ketemutrue else k  k + 1 endif endwhile { k > n or ketemu } if ketemu then { x ditemukan } idxk idx { x tidak ditemukan } RMB/CSG3F3

34 RMB/CSG3F3

35 Contoh 4. Hitung kompleksitas waktu algoritma berikut berdasarkan jumlah operasi kali.

36 Jawaban Untuk j = n, jumlah operasi perkalian = n
j = 1, jumlah operasi perkalian = 1 Jumlah operasi perkalian seluruhnya adalah = n + n/2 + n/4 + …  deret geometri

37 Exercise Determine the time complexity of best, average, and worst case of binary searching RMB/CSG3F3

38 Referensi Levitin, Anany. Introduction to the design and analysis of algorithm. Addison Wesley. 2003 Munir,Rinaldi. Diktat Strategi Algoritmik IF2251. Departemen Teknik Informatika. Institut Teknologi Bandung. 2006 RMB/CSG3F3

39 kompleksitas waktu asimptotik
Next will be… kompleksitas waktu asimptotik RMB/CSG3F3


Download ppt "Algorithm complexity Lesson 4 CSG3F3."

Presentasi serupa


Iklan oleh Google