• Tidak ada hasil yang ditemukan

Desain dan Analisis Algoritma

N/A
N/A
Protected

Academic year: 2022

Membagikan "Desain dan Analisis Algoritma"

Copied!
12
0
0

Teks penuh

(1)

Desain dan Analisis Algoritma

Pertemuan 6

Brute Force

(2)

Salah satu teknik desain algoritma

Brute Force

A straightforward approach to solving problems, usually directly based on the problem statement and definitions of the concepts involved

Examples:

1.Computing a

n

(a > 0, n a nonnegative integer) 2.Computing n!

3.Searching for a key of a given value in a list

(3)

Apa sorting itu?

A

0

≤ A

1

≤ A

2

≤ … A

n-1

≤ A

n

Brute Force Sorting

Perhatikan bahwa setelah sorting :

A0 merupaka elemen dengan nilai terkecil

A1 merupaka elemen dengan nilai terkecil setelah A0

A merupaka elemen dengan nilai terbesar

(4)

Dengan definisi di atas, susunlah algoritma brute force untuk mensorting A[0..n-1]

Brute Force Sorting

(5)

Brute Force Sorting

(6)

Selection Sort

(7)

Analisalah kompleksitas waktu selection sort Ө(n

2

)

Selection Sort

(8)

Apa sorting itu?

A

0

≤ A

1

≤ A

2

≤ … A

n-1

≤ A

n

Alternative Brute Force Sorting

Perhatikan bahwa setelah sorting :

A

0

≤ A

1

A

1

≤ A

2

A

2

≤ A

3

(9)

Bubble Sort

Algorithm bubbleSort(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]

(10)

Analisalah kompleksitas waktu bubble sort Ө(n

2

)

Bubble Sort

(11)

Rarely a source of clever or efficeient algorithm BUT important algorithm design strategy

 Applicable to a very wide variety of problems

 Yields reasonable algorithms of at least some practical value with no limitation of instance size

 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

Brute Force

(12)

1. Tugas untuk pertemuan 7 dapat didownload di mariefh.lecture.ub.ac.id

2. Dipresentasikan oleh mahasiswa dengan nomor_urut_absen % 10 == 2

Tugas

Referensi

Dokumen terkait

Dan di RUU KUHP, itu juga hampir sama dari pasal 563, itu 9 tahun dan dari pasal 588 itu 12 tahun, sehingga dengan satu periode yang tidak tegas ini dan dengan dibarengi

This report addresses the urgency for under- standing the rapidly changing Arctic by connecting the dots among future science opportunities and the infrastructure needed to make

Dengan pendekataan tersebut diharapkan kebutuhan tata ruang dan organisasi ruang untuk kegiatan adat bagi masyarakat modern suku Batak Toba terpenuhi dan juga

Brand Image Kawasan Maribaya Sebagai Objek Wisata Berwawasan Lingkungan (Ekowisata) Universitas Pendidikan Indonesia | repository.upi.edu..

[r]

[r]

by combining thick-film, thin-film and polymer- film sensor elements with a signal processing ASIC within a single package, which should be useful for all sensor types.. T he

Sex Education terhadap Kesehatan Reproduksi pada Remaja Putri usia 16 tahun-19 tahun di SMAN 3 Bangkalan adalah sebagai berikut : 1) Mayoritas 57 (85,1% ) remaja putri