12-crs-0106 revised 8 feb 2013 csg523/ desain dan analisis algoritma mathematical analysis of...
TRANSCRIPT
![Page 1: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/1.jpg)
CSG523/ Desain dan Analisis Algoritma
Mathematical Analysis of Nonrecursive Algorithm
Intelligence, Computing, Multimedia (ICM)
![Page 2: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/2.jpg)
RMB/CSG5232 5/3/2008
What would the complexity be ?
1. 5n comparisons O ( ? )
2. n+10 comparisons O ( ? )
3. 0.6n+33 comparisons O ( ? )
4. 5 comparisons O ( ? )
5. Log2n + 1 comparisons O ( ? )
6. 2n3+n+5 comparisons O ( ? )
7. 3log2n + 2n + 3 comparisons O ( ? )
![Page 3: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/3.jpg)
RMB/CSG5234 5/3/2008
Example 1. Consider the problem of finding the value of the largest element in a list of n numbers. For simplicity, list is implemented as an array.
![Page 4: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/4.jpg)
RMB/CSG5235 5/3/2008
ALGORITHM MaxElement(A[0..n-1])
//determines the value of the largest element in a given array
//input:an array A[0..n-1] of real numbers
//output:the value of the largest element in A
maxval A[0]
for i 1 to n-1
if A[i]>maxval
maxvalA[i]
return maxval
![Page 5: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/5.jpg)
RMB/CSG5236 5/3/2008
The algorithm’s basic operation is comparison A[i]>maxval
C(n) is number of times the comparison is executed.
![Page 6: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/6.jpg)
RMB/CSG5237 5/3/2008
)(11)(1
1
nnnCn
i
![Page 7: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/7.jpg)
RMB/CSG5238 5/3/2008
Two basic rules of sum manipulation
(R2) )(
(R1)
u
i
u
iii
u
iii
u
ii
u
ii
baba
acca
1 11
11
![Page 8: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/8.jpg)
RMB/CSG5239 5/3/2008
Two summation formulas
(S2) )()(
(S1) where
22
0 1 2
1
2
121
11
nnnn
nii
ullu
n
i
n
i
u
li
![Page 9: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/9.jpg)
RMB/CSG52310 5/3/2008
![Page 10: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/10.jpg)
RMB/CSG52311 5/3/2008
What about (n2) in worst case ? Is it correct ?
)()())((
)(
))(()()(
)()()()(
222
2
0
2
0
2
0
2
0
2
0
2
0
1
1
2
1
2
1
2
121
2
12111
11111
nOnnnnn
n
nnnin
ininnC
n
i
n
i
n
i
n
i
n
i
n
i
n
ijworst
![Page 11: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/11.jpg)
RMB/CSG52312 5/3/2008
Faster way
2
12
12112
0
nnS
nninn
i
)()(
...)()()(
![Page 12: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/12.jpg)
RMB/CSG52313 5/3/2008
Example 3
![Page 13: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/13.jpg)
RMB/CSG52314 5/3/2008
Total number of multiplication M(n)
31
0
21
0
1
0
1
0
1
0
1
01
nnn
nM
n
i
n
i
n
j
n
i
n
j
n
k
)(
![Page 14: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/14.jpg)
RMB/CSG52315 5/3/2008
Estimation the running time of the algorithm on a particular machine
333 nccncnc
nAcnMcnT
amam
am
)(
)()()(
![Page 15: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/15.jpg)
RMB/CSG52316 5/3/2008
![Page 16: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/16.jpg)
RMB/CSG52317 5/3/2008
The number of times the comparison n>1 will be executed is actually
[log2n] + 1
![Page 17: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/17.jpg)
RMB/CSG52318 5/3/2008
Exercises
Algorithm mystery(n)
//input: nonnegative integer n
S 0
for i 1 to n
s s+i*i
return s
![Page 18: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/18.jpg)
RMB/CSG52319 5/3/2008
What does this algorithm compute ?
What is its basic operation ?
How many times is the basic operation be executed ?
What is the efficiency class ?
![Page 19: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/19.jpg)
RMB/CSG52320 5/3/2008
ALGORITHM GE(A[0..n-1,0..n])
//Input: an n-by-n+1 matrix A[0..n-1,0..n]
for i0 to n-2 do
for j i+1 to n-1 do
for k i to n do
A[j,k]A[j,k]-A[i,k]*A[j,i]/A[i,i]
Find the time efficiency class of this algorithm
![Page 20: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/20.jpg)
RMB/CSG52321 5/3/2008
Determine the asymptotic complexityint sum = 0; int num = 35;
for (int i=1; i<=2*n; i++) {
for (int j=1; j<=n; j++) {
num += j*3;
sum += num;
}
}
for (int k=1; k<=n; k++) {
sum++;
}
![Page 21: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/21.jpg)
RMB/CSG52322 5/3/2008
Determine the asymptotic complexityint sum = 0; int num = 35;
for (int i=1; i<=2*n; i++) {
for (int j=1; j<=n; j++) {
num += j*3;
sum += num;
}
}
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
for (int k=1; k<=n; k++)
num += j*3;
![Page 22: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/22.jpg)
RMB/CSG52323 5/3/2008
Determine the asymptotic complexity
int sum = 0;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) { sum++;
}
}
![Page 23: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/23.jpg)
RMB/CSG52324 5/3/2008
Determine the asymptotic complexity
for (i=1; i<n; i++)
sum++;
for (i=1; i<n; i=i+2)
sum++;
for (i=1; i<n; i++)
for (j=1; j < n/2; j++)
sum++;
![Page 24: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/24.jpg)
RMB/CSG52325 5/3/2008
Calculating (cont.)for (i=1; i<n; i=i*2)
sum++;
for (i=0; i<n; i++)
for (j = 0; j<i; j++)
sum++;
![Page 25: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/25.jpg)
RMB/CSG52326 5/3/2008
Referensi
Levitin, Anany. Introduction to the design and analysis of algorithm. Addison Wesley. 2003
![Page 26: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/26.jpg)
RMB/CSG52327 5/3/2008
Next..
Mathematical Analysis of Recursive Algorithm
![Page 27: 12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia](https://reader035.vdocuments.net/reader035/viewer/2022062422/56649ef65503460f94c0a02d/html5/thumbnails/27.jpg)
THANK YOU