design and a n alysis of algorithm introduction
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/1.jpg)
Design and Analysis of AlgorithmIntroduction
Aryo Pinandito, ST, M.MT - PTIIK UB
![Page 2: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/2.jpg)
Algoritma Apa itu Algoritma? Kenapa memerlukan algoritma?
Asal Usul Kata Kata algoritma dari nama Abu Ja'fat Mohammed
Ibn Musa al-Khowarizmi, seorang ilmuan Persia yang menulis buku berjudul Kitab al jabr w'al-muqabala (rules of restoration and reduction) sekitar tahun 825 Masehi
Tahun 1950 istilah algorithm selalu diasosiasikan dengan Euclid's algorithm, yaitu suatu proses yang menjelaskan cara mencari bilangan pembagi terbesar untuk dua buah bilangan.
![Page 3: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/3.jpg)
Definisi Algoritma Merriam-Webster's Collegiet Dictionary istilah
algorithm diartikan sebagai prosedur langkah demi langkah untuk memecahkan masalah atau penyelesaian suatu tugas khususnya dengan menggunakan bantuan komputer
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
![Page 4: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/4.jpg)
Syarat Algoritma Menurut Donald E Knuth (The Art of Computer
Programming), algoritma harus memenuhi persyaratan berikut: Input:
Memiliki nol atau lebih masukan dari luar. Output
Memiliki minimal satu buah keluaran. Definiteness (pasti)
Memiliki instruksi-instruksi yang jelas dan tidak ambigu. Finiteness (ada batas):
Memiliki titik berhenti (stopping role) Effectiveness (tepat dan efisien)
Sebisa mungkin harus dapat dilaksanakan dan efektif.
![Page 5: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/5.jpg)
Algorithm Definition Overview Algoritma mendeskripsikankan urutan
langkah-langkah yang diperlukan untuk menyelesaikan suatu permasalahan dan memiliki ciri-ciri sebagai berikut; Selalu memiliki terminasi/langkah akhir Setiap langkah dinyatakan secara jelas, tegas,
dan tidak bermakna ganda (ambigu) Setiap langkah sederhana, sehingga kinerjanya
efisien Memberikan hasil (output), mungkin dengan satu
atau tanpa input.
![Page 6: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/6.jpg)
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
![Page 7: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/7.jpg)
Algoritma dalam Kerangka Penyelesaian Permasalahan
Permasalahan SolusiPenyelesai
anMasalah
AlgoritmaSource Code
ProgramExecutable
Code
![Page 8: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/8.jpg)
Algoritma: Kasus I Terdapat ember A yang berisi cairan biru dan
ember B yang berisi cairan kuning. Misalkan ada sesorang yang ingin menukarkan isi cairan dari kedua ember tersebut bagaimana caranya?
![Page 9: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/9.jpg)
Algoritma: Kasus II Ada dua buah ember dengan kapasitas 5 liter
dan 3 liter. Gunakan dua buah ember tersebut untuk mendapatkan tepat 4 liter air.
![Page 10: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/10.jpg)
Algoritma: Kasus III Misalkan seorang pemuda tiba ditepisebuah sungai.
Pemuda tersebut membawa seekor kambing, seekor serigala, dan sekeranjang sayur. Mereka hendak menyeberangi sungai. Pemuda itu menemukan sebuah perahu kecil yang hanya dapat memuat satu bawaannya setiap kali menyeberang. Situasinya dipersulit dengan kenyataan bahwa serigala tidak dapat ditinggal berdua dengan kambing (karena serigala akan memangsa kambing) atau kambing tidak dapat ditinggal berdua dengan sekeranjang sayur (karena kambing akan memakan sayur).
Bagaimana cara menyeberangkan pemuda dan seluruh bawaannya dengan selamat?
![Page 11: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/11.jpg)
Notasi algoritmik Menggunakan uraian kalimat deskriptif Flow chart Pseudo code
![Page 12: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/12.jpg)
12
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
![Page 13: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/13.jpg)
13
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
![Page 14: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/14.jpg)
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?
![Page 15: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/15.jpg)
Kompleksitas algoritma The complexity of an algorithm is simply the
amount of work the algorithm performs to complete its task.
Ukuran yang digunakan untuk menyatakan keefektifan sebuah algoritma
Ukuran yang digunakan untuk mengukur seberapa besar pertumbuhan komputasi sebuah algoritma
Asymptotic Notations: O (big oh) (big omega) (big theta)
![Page 16: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/16.jpg)
Example: The Minimum Number Problem Input: a sequence of integers stored in
array. Problem: Output the minimum.
Algorithm: Search
![Page 17: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/17.jpg)
Algorithm A
![Page 18: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/18.jpg)
Algorithm Bcopy the input a to array t1; assign n size of input;
While n > 1For i 1 to n/2t2[ i ] min (t1 [ 2*i ], t1[ 2*i + 1] );copy array t2 to t1;n n/2;
Output t2[1];
![Page 19: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/19.jpg)
19
Visualization of Algorithm B8956 1134 720
6 5 8 7
5 7
5
Loop 1
Loop 2
Loop 3
![Page 20: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/20.jpg)
20
Algorithm C Using sort method to sort the input in
increasing order and return the first element of the sorted data.
8956 1134 720
5 6 7 8 9 11 20 34
Sorting black box
![Page 21: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/21.jpg)
21
Algorithm D
For each element, test whether it is the minimum.
![Page 22: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/22.jpg)
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?
![Page 23: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/23.jpg)
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.
What do we need?
![Page 24: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/24.jpg)
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
1000500Input Size
Tb (n)
Ta (n)
4
0
2
Tc (n)
Run
ning
tim
e
(sec
ond)
Td(n)
Time vs. Size of Input
![Page 25: Design and A n alysis of Algorithm Introduction](https://reader034.vdocuments.us/reader034/viewer/2022051420/56815f5d550346895dce3fd1/html5/thumbnails/25.jpg)
Terima KasihThank
You
Danke Gratias
Merci
ありがとうございます
감사합니다 Kiitos
谢谢ًشكرا
Grazias
धन्यवाद