Strategi Algoritma Kuliah 1 : Peran Algoritma

Slides:



Advertisements
Presentasi serupa
Desain Dan Analisis Algoritma
Advertisements

BAB I DASAR-DASAR ALGORITMA
Design and Analysis of Algorithm Recursive Algorithm Analysis
1 Algoritma Bahasa Pemrograman dan Bab 1.1. Pengertian Algoritma.
BAB I DASAR-DASAR ALGORITMA
BAB I DASAR-DASAR ALGORITMA. ALGORITMA An algorithm is “a precise rule (or set of rules) specifying how to solve some problem.” (thefreedictionary.com)
Function.
Modul-8 : Algoritma dan Struktur Data
Pemrograman Berorientasi Objek Bab 1 – Pemrograman Terstruktur.
Pertemuan 3 LINKED LIST (PART 2) Struktur Data Departemen Ilmu Komputer FMIPA-IPB 2009.
2. Introduction to Algorithm and Programming
Fungsi Lecture 7. Motivation Complexity of programming problem  more difficult to consider the solution as a whole  clue: dividing the problem into.
Diberikan pada Kuliah Sela Teknik Informatika - Universitas Muhammadiyah Malang Tahun 2011.
Desain dan Analisis Algoritma
Testing Levels. Activities of Test Engineer Test engineer is an information technology professional who is in charge of ane or more technical test activities,
1 DATA STRUCTURE “ STACK” SHINTA P STMIK MDP APRIL 2011.
BLACK BOX TESTING.
Testing Implementasi Sistem Oleh :Rifiana Arief, SKom, MMSI
1 Diselesaikan Oleh KOMPUTER Langkah-langkah harus tersusun secara LOGIS dan Efisien agar dapat menyelesaikan tugas dengan benar dan efisien. ALGORITMA.
Organisasi dan arsitektur komputer
Ruang Contoh dan Peluang Pertemuan 05
PERTEMUAN KE-6 UNIFIED MODELLING LANGUAGE (UML) (Part 2)
HAMPIRAN NUMERIK SOLUSI PERSAMAAN NIRLANJAR Pertemuan 3
1 HAMPIRAN NUMERIK SOLUSI PERSAMAAN LANJAR Pertemuan 5 Matakuliah: K0342 / Metode Numerik I Tahun: 2006 TIK:Mahasiswa dapat meghitung nilai hampiran numerik.
1 Pertemuan 11 Function dari System Matakuliah: M0446/Analisa dan Perancangan Sistem Informasi Tahun: 2005 Versi: 0/0.
9.3 Geometric Sequences and Series. Objective To find specified terms and the common ratio in a geometric sequence. To find the partial sum of a geometric.
OPERATOR DAN FUNGSI MATEMATIK. Operator  Assignment operator Assignment operator (operator pengerjaan) menggunakan simbol titik dua diikuti oleh tanda.
Jaringan Nirkabel Bab #5 – Enkoding Sinyal.
DIG1G3 Implementasi Struktur Data
Induksi Matematika.
OPERASI PERKALIAN.
CSG523/ Desain dan Analisis Algoritma
Strategi Algoritma Kuliah 2 : Kompleksitas Algoritma
Rekayasa Perangkat Lunak Class Diagram
Branch and Bound Lecture 12 CS3024.
Konsep pemrograman LOOP
User (Pengguna) User = a person who use an IRS
CSG523/ Desain dan Analisis Algoritma
Pengujian Hipotesis (I) Pertemuan 11
CLASS DIAGRAM.
Dasar-Dasar Pemrograman
CPU ARITHMATIC.
Faktor analisa algoritma
Review Operasi Matriks
Algoritma.
Analisis dan Perancangan Algoritma Kuliah 4 : Asymptotic pd Kasus
Algorithms and Programming Searching
MATERI PERKULIAHAN ANALISIS ALGORITMA
Desain dan Analisis Algoritma
Recursive function.
Strategi Algoritma Kuliah 3 : Algoritma Efisien
Teknik Pengujian Software
Manajemen Proyek Perangkat Lunak (MPPL)
Master data Management
Pertemuan 4 CLASS DIAGRAM.
A SMALL TRUTH TO MAKE LIFE 100%. Hard Work H+A+R+D+W+O+R+K = 98% Knowledge K+N+O+W+L+E+D+G+E = 96%
How Can I Be A Driver of The Month as I Am Working for Uber?
Simultaneous Linear Equations
Desain & Analisis Algoritma
Analisis Algoritma E. Haodudin Nurkifli Teknik Informatika
Aplikasi Graph Minimum Spaning Tree Shortest Path.
Algoritma & Pemrograman 1 Achmad Fitro The Power of PowerPoint – thepopp.com Chapter 3.
Lesson 2-1 Conditional Statements 1 Lesson 2-1 Conditional Statements.
By Yulius Suprianto Macroeconomics | 02 Maret 2019 Chapter-5: The Standard of Living Over Time and A Cross Countries Source: http//
Perulangan (Loop) Oleh : Tim Teaching
Right, indonesia is a wonderful country who rich in power energy not only in term of number but also diversity. Energy needs in indonesia are increasingly.
Rank Your Ideas The next step is to rank and compare your three high- potential ideas. Rank each one on the three qualities of feasibility, persuasion,
Draw a picture that shows where the knife, fork, spoon, and napkin are placed in a table setting.
2. Discussion TASK 1. WORK IN PAIRS Ask your partner. Then, in turn your friend asks you A. what kinds of product are there? B. why do people want to.
Algorithms. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The main aim of this lecture.
Transcript presentasi:

Strategi Algoritma Kuliah 1 : Peran Algoritma E. Haodudin Nurkifli Teknik Informatika Universitas Ahmad Dahlan 8-Oct-17

Penghargaan Hand out kuliah Strategi Algoritma ini merupakan ringkasan dari berbagai sumber, yang berkaitan dengan Struktur dan analisis algoritma, Desain and Analisis Algorithm Komputer dari berbagai penjuru. Saya tidak mudah mengingat sumber-sumber tersebut. Namun saya sampaikan penghargaan yang setingginya atas jasa mereka, dan semoga bermannfaat.

Algoritma + Struktur Data = Program Konsep Dasar Menurut Niclaus Wirth : Yang akhirnya ditulis dalam bukunya Algoritma + Struktur Data = Program Efisien Space/memory Time/proses Engineering product

Timing Wild Software Schedule Dalam menghasilkan PROGRAM sebagai engineering product dlm bidang informatika / komputer, terdapat apa yg dikenal dengan Timing Wild Software Schedule Secara umum Terdapat dua hal yaitu : Man hour (waktu penyelesaian) Costing (biaya)

Costing Software Apa parameter biaya pengembangan software ? Per bit / byte Per statement Per modul Per baris Per user interface ?

Apa yg ada pada berbagai alat berikut Hand phone : antara HP yg satu dengan yg lain memiliki feature dan kinerja yg berbeda Alat rumah tangga ke arah komputasi Mesin cuci : pengontrolan dgn control panelnya Otomotif Tipe mobil baru dengan komputasi : pengaturan gas tanpa kabel, kopling, pengaturan bahan bakar Pengaturan Lift gedung tinggi De el el

Apakah perbedaan unjuk kerja pada HP tersebut dibedakan atas besarnya media simpan yang ada? Apakah kemampuan control panel pada berbagai alat rumah tangga memerlukan media simpan yg besar? Apakah pengaturan otomasi pada mesin mobil bergantung pd kapasitas media simpan digitalnya? Apakah otomasi pengaturan lift pada gedung tinggi membutuhkan media simpan digital yg besar?

Kapasitas Media simpan digitalnya ? Algoritma ? Programnya ? ……? Apa yg menentukan unjuk kerja mereka ? Struktur data ? Kapasitas Media simpan digitalnya ? Algoritma ? Programnya ? ……?

Algoritma Peran Algoritma Dalam mengembangkan berbagai alat kebutuhan manusia ke arah komputasi yg lebih berperan adalah Algoritma Bukan Kemampuan / Kapasitas media simpan yg digunakan untuk menyimpan Struktur Data

Lanjt Pengembangan Media simpan untuk struktur data Bersifat Vertikal Pengembangan Algoritma Bersifat Horisontal Horisontal : -Variatif dan fleksibel : terbuka untuk pengembangan / implementasi dalam semua bidang Vertikal : -Monoton, sekali ada yg mengembangkan ya sudah

Lanjt Pengembangan Algoritma masih sangat terbuka untuk semua bidang kehidupan Pertanian Kesehatan Keamanan Pendidikan Manajemen …. ?

Lanjt Analisis Mendasari Mengembangkan Memperbaiki Meningkatkan implementasi Memahami Menjelaskan … ? Mendasari Analisis

Algoritma ? Algoritma Resep urutan proses yg baik dan benar dalam bentuk langkah komputasi untuk menghasilkan sesuatu Urutan proses Langkah komputasi benar Menghasilkan sesuatu Suatu cara spesifik untuk memecahkan dengan pasti suatu persoalan (Webster Dictionary)

Program ? Program merupakan ekspresi / implementasi algoritma dalam bahasa pemrograman tertentu Kumpulan perintah yang mana komputer akan menjalankannya dalam menyelesaikan masalah

Beberapa aplikasi Persoalan teknik Strategi algoritma dapat diaplikasikan/dicontohkan pada proses : sorting Searching data retrieval network routing Games developing Graph dll

Pelajaran Algoritma How to devise algorithms Bagaimana Merencanakan algoritma ? How to express algorithms Bagaimana menjelaskan algoritma How to validate algorithms Bagaimana memvalidasi algoritma How to analyze algorithms Bagaimana menganalisa algoritma How to test a program Bagaimana mengetes program

Pentingnya menganalisa Algoritma Perlunya mengenali batasan dari variasi algoritma untuk penyelesaian persoalan Perlunya memahami relasi antara ukuran masalah dan running time Kapankah running program dinyatakan tidak cukup bagus? Perlunya mempelajari bagaimana menganalisa runing time suatu algortima tanpa coding Perlunya mempelajari teknik menulis program yang lebih efisien Need to recognize bottlenecks in code as well as which parts of code are easiest to optimize

Mengapa kita mengalisa sesuatu? Mengerti perilakunya, dan (Pekerjaan -- Memilih,performance / unjuk kerja, memodifikasi) Meningkatkan kinerja (Research)

Apa yang kita analisa atas algoritma? Kebenarannya Apakah relasi antara input dan ouput sesuai dengan kebutuhan algoritma? Kuantitas pekerjaan yang dikerjakan (time complexity) Operasi dasar untuk mengerjakan tugas Jumlah space yg dibutuhkan Memory yang digunakan (space/memory complexity)

Lanjutan Kesederhanaan, Kejelasan Verifikasi dan implementasi. Optimalitas Mungkinkah ia bekerja lebih baik?

Contoh-Contoh Penerapan Algoritma Kompresi file menggunakan Algoritma Huffman code (greedy algorithm) Cryptanalys menggunakan Brucefource ( untuk memecahkan cipertext) Jaringan komputer menggunakan algoritma Minimum Spaning Tree untuk menentukan harga minimum SIG algoritma MST, Dynamic Programming, Color graphing

PERTEMUAN CUKUP

Kompleksitas Kompleksitas algoritma adalah tingkat ke-komplek-an / ke-simple-an jumlah pekerjaan yang dikerjakan algortima untuk melaksanakan suatu pekerjaan tertentu

Model RAM Memiliki satu processor Melaksanakan satu instruksi at a time Setiap instruksi menyita "unit time“ Memiliki operand ukuran tetap Memiliki fixed size storage (RAM / virtual memory dan disk).

Contoh 1: Operasi dasar Apa hasil dari operasi berikut (M div n)*n + (M mod n) = M+n (a) = M*n (b) = n2 (c) = M (d) = n (e)

Contoh 2 : Linear Searching  PR buatlah minimal 2 algoritma / prosedure / fungsi / pseudocode / program untuk melakukan pencarian (searching) suatu nilai x dalam array A, misalnya A=(7,3,5,9,4,2,6,8,1,0) 0 1 2 3 4 5 6 7 8 9

Timing Wild Apa yg anda alami ? Hal tersebut merupakan salah satu contoh apa yang disebut Timing Wild Nampaknya sepele, namun diluar yang dibayangkan sebelumnya

(d) A[i]<>x and i<=9 (e) i<=9 and A[i]<>x ? Ketemu :=false i:=0 While …… Do i:=i+1 If i<=9 then ketemu:=true else ketemu:=false ? (a) A[i]<> x (b) A[i]=x (c) A[i]=x and i<=9 (d) A[i]<>x and i<=9 (e) i<=9 and A[i]<>x Apa kontrol perulangan yg tepat digunakan untuk statement tsb : ?

Any Question ?

Contoh Algoritma 8-Oct-17

Apa running time dari algorithm berikut? PUZZLE(x) while x != 1     if x is even      then  x = x / 2      else x = 3x + 1 Sample run:  7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

The Selection Problem (1/2) Problem: diberikan sekelompok n angka, ditentukan angka terbesar ke-k Algoritma 1 Simpan angka dalam array Urutkan array secara descending Hasil angka pada posisi k

The Selection Problem(2/2) Algoritma 2 Simpan angka2, pertama k pada array Urutkan array secara descending Untuk setiap angka sisa, jika angka lebih besar dari angka ke-k,sisipkan angka tsb pd posisi yg benar pd array Hasil angka pada posisi k Mana algorithm yg lebih baik?

Contoh: Algoritma Apa? I.I What is an Algorithm? Problem: Input adlh urutan bil integer yg disimpan dlm array. Outputnya adalah bil minimum. Algoritma INPUT m:= a[1]; for I:=2 to size of input if m > a[I] then m:=a[I]; return s OUTPUT instance 25, 90, 53, 23, 11, 34 11 m Data-Structure

Definisi Masalah Problem: Deskripsi dari hubungan Input-Output Algoritma: Suatu urutan dari langkah computational yang memproses input menjadi output. Struktur Data: metode pengelolaan atas penyimpanan dan pengambilan/pengaksesan data. Our task: Diberikan suatu problem, rancangalah secara baik dan benar suatu algoritma yang menyelesaikan problem tersebut..

Contoh Algoritma A Max:=Y[0]; For i:=1 to n-1 do Problem: Input adlh urutan dari integer yg disimpan dlm array. Outputnya adalah max Algorithm A Max:=Y[0]; For i:=1 to n-1 do 3   If Y[i]>max then max:=Y[i]

Contoh Algoritma B Algoritma ini menggunakan 2 array temporary Max:=0; For i:= 0 to (n div 2)-1 do Begin If X[2*i]>X[(2*i)+1] then bantu:=X[2*i] else bantu:=X[(2*i)+1]; If bantu>Max then Max:=bantu end; If (n mod 2) = 1 then If Max<X[n-1] then Max:=X[n-1];

Visualisasi Algoritma B 34 6 5 9 20 8 11 7 Loop 0 34 9 20 11 Loop 1 34 20 Loop 2 34

Contoh Algoritma C For i:= 0 to (n div 2)-1 do If X[2*i]<X[(2*i)+1] then X[2*i]:=X[(2*i)+1]; For i:= 1 to (n div 2) do If X[i-1]>X[i] then X[i]:=X[i-1];     If (n mod 2) = 1 then If X[1]<X[n-1] then X[i]:=X[n-1];

Contoh Algoritma D Untuk setiap elemen, test kondisinya minimum.

Contoh Pemanfaatan Mengurutkan input secara menaik. Hasil elemen pertama dari data terurut. 8 9 5 6 11 34 7 20 black box Sorting 5 6 7 8 9 11 20 34

Mana algoritma yg lebih baik? Semua algoritma benar, tetapi mana yang terbaik? Mengukur running time (Jumlah operasi yg dibutuhkan). Mengukur jumlah memori yg digunakan. Catatan bahwa peningkatan dari running time algoritma sebagai peningkatan ukuran dari input .

Apa yg kita perlukan? Kebenaran: kondisi penghitungan algoritma Solusi yg benar untuk semua hal Effisiensi : Resources yg dibutuhkan oleh algoritma 1. Time: Jumlah langkah. 2. Space: Jumlah memori yg dibutuhkan “Model” ukuran : Worst case, Average case and Best case.

Time vs. Ukuran Input Diukur dengan parameter jumlah input Algorihtma A,B,C di implementasikan dan dijalankan pada PC Algoritma D is implementasi-kan dan dijalankan oada supercomputer. 4 2 Tc (n) Running time (second) Td(n) Tb (n) Ta (n) 500 1000 Input Size

Methods of Proof Proof by Contradiction Proof by Counterexample Assume a theorem is false; show that this assumption implies a property known to be true is false -- therefore original hypothesis must be true Proof by Counterexample Use a concrete example to show an inequality cannot hold Mathematical Induction Prove a trivial base case, assume true for k, then show hypothesis is true for k+1 Used to prove recursive algorithms

Review: Induction Suppose S(k) is true for fixed constant k Often k = 0 S(n)  S(n+1) for all n >= k Then S(n) is true for all n >= k

Proof By Induction Claim:S(n) is true for all n >= k Basis: Show formula is true when n = k Inductive hypothesis: Assume formula is true for an arbitrary n Step: Show that formula is then true for n+1

Induction Example: Gaussian Closed Form Prove 1 + 2 + 3 + … + n = n(n+1) / 2 Basis: If n = 0, then 0 = 0(0+1) / 2 Inductive hypothesis: Assume 1 + 2 + 3 + … + n = n(n+1) / 2 Step (show true for n+1): 1 + 2 + … + n + n+1 = (1 + 2 + …+ n) + (n+1) = n(n+1)/2 + n+1 = [n(n+1) + 2(n+1)]/2 = (n+1)(n+2)/2 = (n+1)(n+1 + 1) / 2

Induction Example: Geometric Closed Form Prove a0 + a1 + … + an = (an+1 - 1)/(a - 1) for all a  1 Basis: show that a0 = (a0+1 - 1)/(a - 1) a0 = 1 = (a1 - 1)/(a - 1) Inductive hypothesis: Assume a0 + a1 + … + an = (an+1 - 1)/(a - 1) Step (show true for n+1): a0 + a1 + … + an+1 = a0 + a1 + … + an + an+1 = (an+1 - 1)/(a - 1) + an+1 = (an+1+1 - 1)/(a - 1)

Induction We’ve been using weak induction Strong induction also holds Basis: show S(0) Hypothesis: assume S(k) holds for arbitrary k <= n Step: Show S(n+1) follows Another variation: Basis: show S(0), S(1) Hypothesis: assume S(n) and S(n+1) are true Step: show S(n+2) follows

Basic Recursion Base case: value for which function can be evaluated without recursion Two fundamental rules Must always have a base case Each recursive call must be to a case that eventually leads toward a base case

Bad Example of Recursion Example of non-terminating recursive program (let n=1) int bad(unsigned int n) { if(n == 0) return 0; else return(bad(n/3 + 1) + n - 1); }

Recursion(1/2) Problem: write an algorithm that will strip digits from an integer and print them out one by one void print_out(int n) { if(n < 10) print_digit(n); /*outputs single-digit to terminal*/ else{ print_out(n/10); /*print the quotient*/ print_digit(n%10); /*print the remainder*/ }

Recursion(2/2) Prove by induction that the recursive printing program works: basis: If n has one digit, then program is correct hypothesis: Print_out works for all numbers of k or fewer digits case k+1: k+1 digits can be written as the first k digits followed by the least significant digit The number expressed by the first k digits is exactly floor( n/10 )? which by hypothesis prints correctly; the last digit is n%10; so the (k+1)-digit is printed correctly By induction, all numbers are correctly printed

Recursion Don't need to know how recursion is being managed Recursion is expensive in terms of space requirement; avoid recursion if simple loop will do Last two rules Assume all recursive calls work Do not duplicate work by solving identical problem in separated recursive calls Evaluate fib(4) -- use a recursion tree fib(n) = fib(n-1) + fib(n-2)

What is Algorithm Analysis? How to estimate the time required for an algorithm Techniques that drastically reduce the running time of an algorithm A mathemactical framwork that more rigorously describes the running time of an algorithm

Running time for small inputs

Running time for moderate inputs

Important Question Is it always important to be on the most preferred curve? How much better is one curve than another? How do we decide which curve a particular algorithm lies on? How do we design algorithms that avoid being on the bad curves?

Algorithm Analysis(1/5) Measures the efficiency of an algorithm or its implementation as a program as the input size becomes very large We evaluate a new algorithm by comparing its performance with that of previous approaches Comparisons are asymtotic analyses of classes of algorithms We usually analyze the time required for an algorithm and the space required for a datastructure

Algorithm Analysis (2/5) Many criteria affect the running time of an algorithm, including speed of CPU, bus and peripheral hardware design think time, programming time and debugging time language used and coding efficiency of the programmer quality of input (good, bad or average)

Algorithm Analysis (3/5) Programs derived from two algorithms for solving the same problem should both be Machine independent Language independent Environment independent (load on the system,...) Amenable to mathematical study Realistic

Algorithm Analysis (4/5) In lieu of some standard benchmark conditions under which two programs can be run, we estimate the algorithm's performance based on the number of key and basic operations it requires to process an input of a given size For a given input size n we express the time T to run the algorithm as a function T(n) Concept of growth rate allows us to compare running time of two algorithms without writing two programs and running them on the same computer

Algorithm Analysis (5/5) Formally, let T(A,L,M) be total run time for algorithm A if it were implemented with language L on machine M. Then the complexity class of algorithm A is O(T(A,L1,M1) U O(T(A,L2,M2)) U O(T(A,L3,M3)) U ... Call the complexity class V; then the complexity of A is said to be f if V = O(f) The class of algorithms to which A belongs is said to be of at most linear/quadratic/ etc. growth in best case if the function TA best(n) is such (the same also for average and worst case).

Asymptotic Performance In this course, we care most about asymptotic performance How does the algorithm behave as the problem size gets very large? Running time Memory/storage requirements Bandwidth/power requirements/logic gates/etc.

Asymptotic Notation By now you should have an intuitive feel for asymptotic (big-O) notation: What does O(n) running time mean? O(n2)? O(n lg n)? How does asymptotic running time relate to asymptotic memory usage? Our first task is to define this notation more formally and completely

Analysis of Algorithms Analysis is performed with respect to a computational model We will usually use a generic uniprocessor random-access machine (RAM) All memory equally expensive to access No concurrent operations All reasonable instructions take unit time Except, of course, function calls Constant word size Unless we are explicitly manipulating bits

Input Size Time and space complexity This is generally a function of the input size E.g., sorting, multiplication How we characterize input size depends: Sorting: number of input items Multiplication: total number of bits Graph algorithms: number of nodes & edges Etc

Running Time Number of primitive steps that are executed Except for time of executing a function call most statements roughly require the same amount of time y = m * x + b c = 5 / 9 * (t - 32 ) z = f(x) + g(y) We can be more exact if need be

Analysis Worst case Provides an upper bound on running time An absolute guarantee Average case Provides the expected running time Very useful, but treat with care: what is “average”? Random (equally likely) inputs Real-life inputs

Function of Growth rate