introduction to algorithms

24
1 Introduction to Algorithms

Upload: kineks

Post on 22-Jan-2016

38 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Algorithms. Topik. Solving problems Algorithms Nilai dan v ariabel. Bgmn kita memecahkan masalah ?. Langsung kerjakan Tabak dan untung-untungan Trial error Pengalaman "Scientifically“ = dg cara ilmiah. Analysis. Problem specification. Design. Algorithm. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Algorithms

1

Introduction to Algorithms

Page 2: Introduction to Algorithms

2

Topik

• Solving problems

• Algorithms

• Nilai dan variabel

Page 3: Introduction to Algorithms

3

Bgmn kita memecahkan masalah ?

• Langsung kerjakan

• Tabak dan untung-untungan

• Trial error

• Pengalaman

• "Scientifically“ = dg cara ilmiah

Page 4: Introduction to Algorithms

4

0100111010110010101010101001010101010100110010101010101001011010011101010101010010010111010011110101010111110101010001101…

sterilize(saw,alcohol);raise_hammer();lower hammer(fast);start(saw);/* etc. etc. */

Patient has elevated pressure in anterior parietal lobe

Process memcahkan masalah

Problem

specification

Algorithm

Program

Executable (solution)

Design

Implementation

Compilation

"Doctor, my head hurts"

Analysis

1. Sterilize cranial saw2. Anaesthetize patient3. Remove top of skull4. Get the big spoon...5. etc., etc.

Page 5: Introduction to Algorithms

5

steril(gergaji,alcohol);raise_hammer();lower hammer(fast);start(saw);/* etc. etc. */

Process memcahkan masalah

Problem specification

Algorithm

Program

Executable (solution)

Analysis

Design

Implementation

Compilation

"Dok, kepala saya sakit”

Pasien ada penyumbatan pd anterior parietal lobe.

1. Steril gergaji2. bius3. Potong batok kepala4. Ambil spoon...5. etc., etc.

010011101011001010101010100101010101010011001010101010100101101001110101010101001001011101001111010101011111010101000110100001101...

Page 6: Introduction to Algorithms

6

Process memcahkan masalah

Problem specification

Algorithm

Program

Executable (solution)

Analysis

Design

Implementation

Compilation

Page 7: Introduction to Algorithms

7

Algorithm – DefinisiFrom: Websters Revised Unabridged Dictionary, 1913:

Algorism (Al"go*rism Al"go*rithm) • n. [OE. algorism, algrim, augrim, OF. algorisme, F.

algorithme (cf. Sp. algoritmo, OSp. alguarismo, LL. algorismus)

• Al-Khowarezmi aslinya Abu Ja'far Mohammed ben Musa, ahli arithmetic awal abad 9, bukunya dalam bhs latin algorismus.

Page 8: Introduction to Algorithms

8

• Urutan instruksi untuk menentukan langkah yang di perlukan dalam menyelesaikan suatu tugas.

• Muhammad ibn Musa al-KhwarizmiBerasal dari Khowarezm (sekarang Khiva di

Uzbekistan)

Algorithm

Page 9: Introduction to Algorithms

9Source: http://www.atlapedia.com/online/maps/political/Kazakh_etc.htm

Page 10: Introduction to Algorithms

10

Algorithm– SejarahMuhammad ibn Musa Al-Khwarizmi• Circa 160-230 A.H. (anno Hegirae)

• Circa 780-850 C.E. (Common Era)

Page 11: Introduction to Algorithms

11

Algorithm –Sejarah (lanj)

Muhammad ibn Musa Al-Khwarizmihttp://www-groups.dcs.st-andrews.ac.uk/~history/Mathematicians/Al-Khwarizmi.html

• Buku arithmetic:– Hindu numeration, decimal numbers, use of zero,

method for finding square root– Latin translation (c.1120 CE): “Algoritmi de

numero Indorum”

• Book aljabar algebra– Hisab al-jabr w’al-muqabala

Page 12: Introduction to Algorithms

12

• Urutan langkah yang menggambarkan bagaimana melakukan suatu pekerjaan

Algorithm – Working Definition

[As opposed to actually executing

the instructions]

Page 13: Introduction to Algorithms

13

Algorithm -- Contoh• Resep masakan• Instruksi Assembly • Aturan main game• Instruksi VCR • Deskripsi teknik bela diri• Arahan dari A to B• Pola jahitan • Manual perbaikan mobil

Page 14: Introduction to Algorithms

14

From Algorithms to Programs

Problem

C ProgramC Program

AlgorithmAlgorithm: A sequence of instructions describing how to do a task (or process)

Page 15: Introduction to Algorithms

15

Komponen Algorithm

• Variabel dan Nilai

• Instruksi

• Sequences (Urutan)

• Procedures (Prosedur)

• Selections (Pilihan)

• Repetitions (Perulanagan)

• Documentation

Page 16: Introduction to Algorithms

16

Nilai

• Mewakili kuantitas, jumlah atau pengukuran

• Bisa numeri atau alphabetical (atau lainnya)

• Biasanya memiliki unit yang berhubungan dengan tujuannya

Page 17: Introduction to Algorithms

17

Variabel

TolpesDapat berisi

10 kue

50 grams gula

3 potong roti

dll.

ValuesVariable

• Adalah container untuk nilai – tempat untuk menyimpan nilai

• Contoh :

Page 18: Introduction to Algorithms

18

Batasan Variabel

• Variabel dibatasi oleh nilai tipe yang di spesifikasikan

Page 19: Introduction to Algorithms

19

Komponen AlgorithmNilai dan Variabel

• Instruksi (primitive)

• Sequence (dr instruction)

• Procedure (yg melibatkan instruction)

• Selection (antara instruction)

• Repetition (dr instruction)

• Documentation (disamping instruction)

Page 20: Introduction to Algorithms

20

Instruksi (Primitives)

• Suatu action yang simple...

• ...dan jelas...

• ...komputer mengerti...

• ...dapat diaktualisasikan

Page 21: Introduction to Algorithms

21

Instruksi– Examples

• Take off your shoes

• Count to 10

• Cut along dotted line

• Jahit 1

• Purl 2

• tarik benang pelan-pelan

• Bubuhkan 10 grams arsenic

Directions to perform specific actions on values and variables.

Page 22: Introduction to Algorithms

22

Instruksi -- Application

• Beberapa instruksi dapat hanya di aplikasikan pada nilai atau variabel yang di spesifikasikan.

• Contoh:

Page 23: Introduction to Algorithms

23

Instruksi (Primitives) -- Recommendations

• Jika menulis algorithm, buat instruksi yang simple dan jelas

• Contoh:

Potong ayam kecil-kecil dan masak potongan tersebut pada minyak yang panas

Potong ayam kecil-kecil.

Panaskan minyak.

Masak ayam 5 menit

Page 24: Introduction to Algorithms

24

Instruksi (Primitives)• When writing an algorithm, make the

instructions simple and unambiguous.

• Example:

Potong ayam kecil-kecil dan masak potongan tersebut pada minyak yang panas

Potong ayam kecil-kecil.

Panaskan minyak.

Masak ayam 5 menit

“Urutan” dari instruksi yang simple.