Desain dan Analisis Algoritma Pertemuan 6 Brute Force
Desain dan Analisis Algoritma Pertemuan 6 Brute Force
Brute Force Salah satu teknik desain algoritma A straightforward approach to solving problems, usually directly based on the problem statement and definitions of the concepts involved Examples: 1. Computing an (a > 0, n a nonnegative integer) 2. Computing n! 3. Searching for a key of a given value in a list
Brute Force Sorting Apa sorting itu? A 0 ≤ A 1 ≤ A 2 ≤ … An-1 ≤ An Perhatikan bahwa setelah sorting : A 0 merupaka elemen dengan nilai terkecil A 1 merupaka elemen dengan nilai terkecil setelah A 0 … An merupaka elemen dengan nilai terbesar
Brute Force Sorting Dengan definisi di atas, susunlah algoritma brute force untuk mensorting A[0. . n-1]
Brute Force Sorting
Selection Sort
Selection Sort Analisalah kompleksitas waktu selection sort Ө(n 2)
Alternative Brute Force Sorting Apa sorting itu? A 0 ≤ A 1 ≤ A 2 ≤ … An-1 ≤ An Perhatikan bahwa setelah sorting : A 0 ≤ A 1 ≤ A 2 ≤ A 3 …
Bubble Sort Algorithm bubble. Sort(A[0. . n-1]) //mensorting array A menggunakan bubble sort //input : array A[0. . n-1] //output : array A[0. . n-1] dalam keadaan terurut naik for i ← 0 to n – 2 do for j ← 0 to n – 2 – i do if A[j + 1] < A[j] swap A[j] and A[j + 1]
Bubble Sort Analisalah kompleksitas waktu bubble sort Ө(n 2)
Brute Force Rarely a source of clever or efficeient algorithm BUT important algorithm design strategy v Applicable to a very wide variety of problems v Yields reasonable algorithms of at least some practical value with no limitation of instance size v Expense of designing a more efficient algorithm may be unjustifiable if only a new instances of a problem need to be solved and a brute force algorithm can solve those instances with acceptable speed
Tugas 1. Tugas untuk pertemuan 7 dapat didownload di mariefh. lecture. ub. ac. id 2. Dipresentasikan oleh mahasiswa dengan nomor_urut_absen % 10 == 2
- Slides: 12