Professional Documents
Culture Documents
1.pengantar Kuliah
1.pengantar Kuliah
1.pengantar Kuliah
DAA
Algoritma
terencana, dapat dilakukan, selesai jurus pemecahan masalah penentuan kelas algoritma
Desain Algoritma
Analisis Algoritma
Materi Kuliah
Text Introduction to Algorithms, 2nd edition T. H. Cormen, C. E. Leiserson, R. L. Rivest, and Clifford Stein Published by: MIT Press or McGraw-Hill Introduction to the design and analysis of algorithm Anany Levitin Published by: Addison Wesley
Pokok Bahasan
1.
Algorithmic strategies
1. 2. 3. 4. 5. 6. 7.
2.
3.
4. 5.
8.
6.
9.
Brute-force algorithms Greedy algorithms Divide-and-conquer Backtracking Branch-and-bound Heuristics Pattern matching and string/text algorithms Numerical approximation algorithms Dynamic Programming
5
Contents
Algorithm Design and Analysis Process Important Problem Types The Need of Efficient Algorithm Analysis Framework
Correctness: prove that the algorithm yields a required result for every legitimate input in a finite amount of time
Usually using mathematical induction Can we use simple tracing?
Incorrectness
Approx alg
Programming an algorithm:
Peril: incorrect / inefficient transition Program correctness proving? Practical: testing & debugging
10
Sorting Searching String processing Graph problems Combinatorial problems Geometric problems Numerical problems
11
The problem: rearrange the item of a given list in ascending order In case of records, we need a key There are dozens of sorting algorithms Two properties of sorting algorithms:
Stable: it preserve the relative order of any two equal elements in its input In place: it does not require extra memory, except, possibly, for a few memory units
12
The problem: finding a given value (search key) in a given set Searching algorithms range:
sequential search to binary search (spectacularly efficient, but limited) and algorithm based on representing the set in a different form more conducive to search Very large data set Update: add, edit, delete
Challenges:
13
String = a sequence of characters from alphabet Particular interest: text strings, binary strings, gene sequences etc. One particular problem: string matching
14
Basic graph algorithms: graph traversal, shortest-path, topological sorting for graph with directed edges Some problems are computationally very hard only very small instances can be solved in a realistic amount of time
The problem: find a combinatorial object such as a permutation, a combination, or a subset that satisfies certain constraints and has some desired property The most difficult problems
The number of combinatorial objects typically grows extremely fast with a problems size There are no known exact algorithms for solving such problems in an acceptable amount of time
From a more abstract perspective, TSP & GCP are examples of combinatorial problem
16
Deals with geometric objects: points, lines, polygons etc. Ancient Greek: to construct simple geometric shapes triangles, circles etc. with unmarked ruler and compass Today people: application to computer graphics, robotics, tomography etc. Classic problems:
Closest-pair problem: given n points in the plane, find the closest pair among them
17
Involves mathematical objects of continuous nature: solving equations and system of equations, computing definite integrals, evaluating functions etc. The majority of such mathematical problem can only solved approximately Computer can only represent real number approximately Accumulation of the round-off error Computing industry focus shifting: numerical analysis (in industry & science) to business application (information storage, retrieval, transportation through network, and presentation to users)
18
Suppose that you have an infinitely fast computer equipped with unlimited capacity of free-memory. Do you still have any reason to study algorithm?
19
Absolutely YES!
You still have to demonstrate that your solution method terminates and does so with the correct answer
20
Computers may be fast, but they are not infinitely fast Memory may be cheap, but it is not free. Bounded resources:
These resources must be used wisely, and efficient algorithms will help you do so
21
Efficiency: An Illustration
Insertion sort: takes time roughly equal to c1n2 to sort n items n2 Merge sort: takes (c2 n log2 n) to sort n items n log2 n
c1 < c2 far less significant than the input size n Insertion sort is usually faster than merge sort for small input sizes. Once the input size n becomes large enough, merge sorts advantage of log2 n vs n will more to compensate the difference in constant factors
22
Array to sort: 106 numbers Computer A: 109 inst/sec; running insertion sort; craftiest programmer; codeIS 2n2 Computer B: 107 inst/sec; running merge sort; average programmer, HLL; the codeMS 50 n log2 n Comp A: (2(106)2) / 109 = 2000 sec Comp B: (50.106 log2 106) / 107 100 sec
23
By using an algorithm whose running time grows more slowly, even with a poor compiler, comp B runs 20 faster than A. Lets try to sort 107 numbers
24
Analysis Framework
Measuring an inputs size Unit for Measuring Running Time Orders of Growth Worst-case, Best-case, and Average-case Efficiency
25
Almost all algorithms run longer on larger inputs Its logical to investigate an algorithms efficiency as a function of some parameter n indicating the algorithms input size In most cases, selecting n is straightforward; exp: the size of the list for sorting, searching etc. For the problem of evaluating polynomial of degree n, it will be polynomials degree or the number of its coefficients
26
Example: computing the product of two nby-n matrices Two natural measures:
The matrix order n The total number of elements N in the matrix being multiplied applicable to n-by-m matrices
27
If it examines individual characters of its input the number of characters If it works by processing words the number of words
28
Can we use some standard units of time measurement a second, a millisecond, and so on ?
Drawbacks: dependence on the speed of a particular computer, dependence on the quality of a program, difficulty of clocking the actual running time of the program
One possible approach: to count the number of times each of the algorithms operations is executed difficult & unnecessary
29
Basic Operation
Compute the number of times the basic operation is executed The established framework for analysis of an algorithms time efficiency: counting the number of times the algorithms basic operation is executed on input of size n
30