You are on page 1of 34

ALGORITMA

1
‫أبو عبد هللا محمد بن موسى الخوارزمي‬
‫) ‪( 780 – 850 M‬‬

‫الكتاب المختصر في حساب الجبر والمقابلة‬


Abu Abdullah Muḥammad ibnu Mūsā al-Khawārizmī
( 780 – 850 M )

Al-Khawārizmī
Algorism
Algorithm
Algorithm is a recipe

ALGORITMA
Algorithm
•Commands
Problem
Begining •Iteration Solving

•Decision
•Row-column
elements
ASPEK
PENTING
ALGORITMA
2
FINITENESS
int a=6;
main()
{
while(a>5)
{
cout<<a;
a++;
}
}
Finiteness
Algoritma harus berhenti
setelah melalui beberapa
tahapan (langkah)
DEFINITENESS
How could we
define the
“MIRACLE”?
Definiteness
Setiap langkah harus
didefinisikan secara tepat, tidak
boleh membingungkan (ambigu)
DEFINITENESS
Effectiveness
Setiap algoritma
harus
berhasil-guna
(sangkil/ efektif)
PARADIGMA
ALGORITMA

3
Divide and Conquer
SMALLER SMALLER SMALLER
DIVIDE PROBLEM PROBLEM PROBLEM

Permasalahan
besar dipecah-
pecah menjadi SMALLER
PROBLEM
BIG
SMALLER
PROBLEM
SMALLER
PROBLEM
beberapa PROBLEM
permasalahan
yang lebih kecil/
SMALLER SMALLER SMALLER
sederhana PROBLEM PROBLEM PROBLEM
Divide and Conquer
SMALLER SMALLER SMALLER
SMALLER SMALLER SMALLER
CONQUER PROBLEM
PROBLEM
PROBLEM
PROBLEM
PROBLEM
PROBLEM
SOLVED SOLVED SOLVED

Permasalahan- SMALLER SMALLER SMALLER


SMALLER SMALLER SMALLER
permasalahan PROBLEM
PROBLEM
PROBLEM
PROBLEM
PROBLEM
PROBLEM
SOLVED SOLVED SOLVED
kecil dipecahkan
secara parsial
SMALLER SMALLER SMALLER
SMALLER SMALLER SMALLER
PROBLEM PROBLEM PROBLEM
PROBLEM PROBLEM PROBLEM
SOLVED SOLVED SOLVED
Divide and Conquer
SMALLER SMALLER SMALLER
COMBINE PROBLEM PROBLEM PROBLEM
SOLVED SOLVED SOLVED

Permasalahan
SMALLER
BIG
SMALLER SMALLER
PROBLEM PROBLEM PROBLEM
SOLVED
PROBLEM
SOLVED SOLVED
terpecahkan
SOLVED
SMALLER SMALLER SMALLER
PROBLEM PROBLEM PROBLEM
SOLVED SOLVED SOLVED
CONTOH
DIVIDE &
CONQUEROR
3
Urutkan angka-angka
di bawah ini :
8, 3, 9, 7, 1, 5, 4

SORTING
8 3 2 9 7 1 5 4

8 3 2 9 7 1 5 4

8 3 2 9 71 5 4

8 3 2 9 7 1 5 4
MERGE SORT
3 8 2 9 1 7 4 5

2 3 8 9 1 4 5 7

1 2 3 4 5 7 8 9

SORTING
Dynamic
Algorithm

3
Sometimes, the divide and conquer
approach seems appropriate
but fails to produce
an efficient algorithm

WHY?
This algorithm is commonly used as
an example of the elegance of recursion
as a programming technique.
However, when we examine its time
complexity,
we find it's far from elegant!

WHY?
So this function will take
exponential time!
Algorithms which run in exponential time
are to be avoided at all costs!

WHY?
DYNAMIC
This algorithm solves the problem
of calculating f0 and f1 first,
calculates f2 from these,
then f3 from f2 and f1, and so on.

DYNAMIC
Dynamic Algorithm adalah
1. Memecahan masalah terkecil
2. Menyimpan solusinya
3. Memecahkan masalah yg lebih besar
4. Menyimpan solusinya
5. Memecahkan masalah yg lebih
besar lagi

DYNAMIC
FREE LUNCH?
NO
THERE IS NO FREE LUNCH!
Dynamic Algorithm akan memakan
memori untuk menyimpan hasil-hasil
problem kecil tadi.
Trade space for increased speed.

DYNAMIC
Decrease and Conquer:
Selection sort
• Misalkan tabel A berisi elemen-elemen berikut:

• Langkah-langkah pengurutan dengan Selection


Sort:

You might also like