250 likes | 379 Views
Design and A n alysis of Algorithm Introduction. Aryo Pinandito, ST, M.MT - PTIIK UB. Algoritma. Apa itu Algoritma ? Kenapa memerlukan algoritma ? Asal Usul Kata
E N D
Design and Analysis of AlgorithmIntroduction Aryo Pinandito, ST, M.MT - PTIIK UB
Algoritma • ApaituAlgoritma? • Kenapamemerlukanalgoritma? AsalUsul Kata • Kata algoritmadarinama Abu Ja'fat Mohammed Ibn Musa al-Khowarizmi, seorangilmuan Persia yang menulisbukuberjudulKitab al jabrw'al-muqabala (rules of restoration and reduction) sekitartahun 825 Masehi • Tahun1950 istilahalgorithmselaludiasosiasikandenganEuclid's algorithm, yaitusuatu proses yang menjelaskancaramencaribilanganpembagiterbesaruntukduabuahbilangan.
DefinisiAlgoritma • Merriam-Webster's Collegiet Dictionaryistilahalgorithmdiartikansebagaiprosedurlangkah demi langkahuntukmemecahkanmasalahataupenyelesaiansuatutugaskhususnyadenganmenggunakanbantuankomputer • Step-by-step procedure for calculations. More precisely, it is an effective method expressed as a finite list of well-defined instructions for calculating a function
SyaratAlgoritma • Menurut Donald E Knuth (The Art of Computer Programming), algoritmaharusmemenuhipersyaratanberikut: • Input: • Memilikinolataulebihmasukandariluar. • Output • Memilikiminimal satubuahkeluaran. • Definiteness (pasti) • Memilikiinstruksi-instruksi yang jelasdantidakambigu. • Finiteness (adabatas): • Memilikititikberhenti (stopping role) • Effectiveness (tepatdanefisien) • Sebisamungkinharusdapatdilaksanakandanefektif.
Algorithm Definition Overview • Algoritmamendeskripsikankanurutanlangkah-langkah yang diperlukanuntukmenyelesaikansuatupermasalahandan memilikiciri-cirisebagaiberikut; • Selalumemilikiterminasi/langkahakhir • Setiaplangkahdinyatakansecarajelas, tegas, dan tidakbermaknaganda (ambigu) • Setiaplangkahsederhana, sehinggakinerjanyaefisien • Memberikanhasil (output), mungkindengansatuatautanpa input.
What is a Program? • A program is the expression of an algorithm in a programming language • a set of instructions which the computer will follow to solve a problem
Algoritma: Kasus I • Terdapat ember A yang berisicairanbirudan ember B yang berisicairankuning. Misalkanadasesorang yang inginmenukarkanisicairandarikedua ember tersebutbagaimanacaranya?
Algoritma: KasusII • Adaduabuah ember dengankapasitas 5 liter dan 3 liter. Gunakanduabuah ember tersebutuntukmendapatkantepat 4 liter air.
Algoritma: KasusIII • Misalkanseorangpemudatibaditepisebuahsungai. Pemudatersebutmembawaseekorkambing, seekorserigala, dansekeranjangsayur. Merekahendakmenyeberangisungai. Pemudaitumenemukansebuahperahukecilyang hanyadapatmemuatsatubawaannyasetiapkali menyeberang. Situasinyadipersulitdengankenyataanbahwaserigalatidakdapatditinggalberduadengankambing(karenaserigalaakanmemangsakambing) ataukambingtidakdapatditinggalberduadengansekeranjangsayur (karenakambingakanmemakansayur). Bagaimanacaramenyeberangkanpemudadanseluruhbawaannyadenganselamat?
Notasialgoritmik • Menggunakanuraiankalimatdeskriptif • Flow chart • Pseudo code
The study of algorithm • How to devise/design algorithms • How to express algorithms • How to validate algorithms • How to analyze algorithms • How to test a program
Importance of analyze algorithm • Need to recognize limitations of various algorithms for solving a problem • Need to understand relationship between problem size and running time • When is a running program not good enough? • Need to learn how to analyze an algorithm's running time without coding it • Need to learn techniques for writing more efficient code • Need to recognize bottlenecks in code as well as which parts of code are easiest to optimize
What do we analyze about them? • Correctness • Does the input/output relation match algorithm requirement? • Amount of work done (aka complexity) • Basic operations to do task • Amount of space used • Memory used • Simplicity, clarity • Verification and implementation. • Optimality • Is it impossible to do better?
Kompleksitas algoritma • The complexity of an algorithm is simply the amount of work the algorithm performs to complete its task. • Ukuran yang digunakanuntukmenyatakankeefektifansebuahalgoritma • Ukuran yang digunakanuntukmengukurseberapabesarpertumbuhankomputasisebuahalgoritma • Asymptotic Notations: • O (big oh) • (big omega) • (big theta)
Example: The Minimum Number Problem • Input: a sequence of integers stored in array. • Problem: Output the minimum. • Algorithm: Search
Algorithm B copy the input a to array t1; assign n size of input; • While n > 1 For i 1 to n/2 t2[i ] min (t1 [ 2*i ], t1[ 2*i + 1] ); copy array t2 to t1; n n/2; • Output t2[1];
Visualization of Algorithm B 7 34 6 5 9 20 8 11 Loop 1 5 8 7 6 Loop 2 7 5 Loop 3 5
7 34 6 5 9 20 8 11 5 6 7 8 9 11 20 34 Algorithm C • Using sort method to sort the input in increasing orderand return the first element of the sorted data. black box Sorting
Algorithm D For each element, test whether it is the minimum.
The algorithms are correct, but which is the best? Measure the running time (number of operations needed). Measure the amount of memory used. Note that the running time of the algorithms increase as the size of the input increases. Which Algorithm Is Better?
What do we need? Correctness: Whether the algorithm computes the correct solution for all instances Efficiency: Resources needed by the algorithm 1. Time: Number of steps. 2. Space: Amount of memory used. Measurement “model”: Worst case, Average case and Best case.
4 Td(n) Tc(n) Running time (second) 2 0 Time vs. Size of Input Measurement parameterized by the size of the input. The algorithms A,B,C are implemented and run in a PC. Algorithms D is implemented and run in a supercomputer. Let Tk( n ) be the amount of time taken by the Algorithm Tb (n) Ta (n) 500 1000 Input Size
감사합니다 Grazias Kiitos Gratias Danke ﺷﻜﺮﺍﹰ 谢谢 TerimaKasih Merci Thank You धन्यवाद ありがとうございます