Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.
-
Upload
rhoda-jones -
Category
Documents
-
view
219 -
download
5
Transcript of Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.
![Page 1: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/1.jpg)
Algorithm DesignNattee Niparnan
Dept. of Computer Engineering,Chulalongkorn University
![Page 2: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/2.jpg)
The CourseMidterm 40%Final 40%Something else 20%
Quiz 10%Lab 10%
![Page 3: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/3.jpg)
Yes, we have labsThis year, we introduce lab
You will be required to participate in “online” activities
Writing code (in C language)
Teacher and TA will help you
![Page 4: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/4.jpg)
TopicsAnalysis
Asymptotic notationBig O analysisNP-Complete
DesignDivide and ConquerDynamic ProgrammingGraph AlgorithmGreedy AlgorithmSearch
There will be labs for each
of these topics
![Page 5: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/5.jpg)
Books : Required Algorithms, S. Dasgupta, C. Papadimitriou
and U. Vazirani, McGraw-Hill, 2008
![Page 6: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/6.jpg)
Books : Supplementalการวิ�เคราะห์และออกแบบอ�ลกอร�ทึ�ม, สมชาย ประส�ทึธิ์��จู�ตระก�ล, NECTEC, 2544
Data Structure & Algorithm Analysis, Mark Allen Weiss.
Introduction to Algorithms 2nd edition, T. Cormen, C. Leiserson, R. Rivest, C. Stein, MIT Press & McGraw-Hill, 2001.
Introduction to Algorithms: A Creative Approach, Udi Manber.
![Page 7: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/7.jpg)
WebWebboard
http://www.cp.eng.chula.ac.th/webboard/viewforum.php?f=18
Lab http://www.nattee.net/teaching/You can also find my slides there
![Page 8: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/8.jpg)
IntroductionChapter 0
![Page 9: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/9.jpg)
What is an algorithm?A precise instruction based on elementary
operationWhich takes something as an input and process
it to some output
Usually to solve some problems
![Page 10: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/10.jpg)
What is Problem?A task with precise description of admissible
input and the “property” of the desired output
E.g., GCDGiven two positive integers (input)Determine GCD of the given integers
(express the property of the desired output) GCD is well defined
![Page 11: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/11.jpg)
Problem InstanceDetermining GCD is a problem
How many actual problems? GCD of 1,2 ? GCD of 234,42? ???
Problem instance A problem with a specific inputE.g., find a GCD of 42 and 14
![Page 12: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/12.jpg)
Purpose of this class“how to design an algorithm for given
problems”AnalysisSynthesis emphasized….
CorrectnessFor any instances, it must produce appropriate
outputEfficient!!
![Page 13: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/13.jpg)
Calculating Fibonacci SequenceFibonacci sequence
1,1,2,3,5,7,8,13,21,34,55,89,144,233,377,610,987,1597,2584
;1:
;1:
;0:
1
0
21
n
n
n
FF
F
nn
n
![Page 14: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/14.jpg)
The ProblemInput:
a positive number NOutput:
Fn (the nth Fibonacci Number)
Example instancesEx. 1: N = 10Ex. 2: N = 15Ex. 3: N = 0
N = -4 is not an instances of this problem!!!
![Page 15: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/15.jpg)
Approach 1Array based
DP (linear)
1 1 2 3 5 8 13 21 34 55
![Page 16: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/16.jpg)
Approach 2
Recursive (exponential)
F(9)
F(8)
F(7)
F(7)
F(6)
F(6)
F(5)
… … … …
![Page 17: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/17.jpg)
Approach 3
Divide and Conquer (logarithmic)
1
0
2
1
11
10
F
F
F
F
1
2
1
1
11
10
n
n
n
n
n
F
F
F
F
![Page 18: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/18.jpg)
Approach 3Find exponential
Divide and Conquer (logarithmic)
odd isn ;
even isn ;2/2/
2/2/
xxx
xxx
nn
nnn
![Page 19: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/19.jpg)
Approach 4
Closed form solution (constant)
5
51
22
51nn
nF
Golden Ratio
![Page 20: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/20.jpg)
ConclusionDifference Design Difference PerformanceThis class emphasizes on designing “efficient
algorithm”
![Page 21: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/21.jpg)
Algorithm AgainIt is the essence of the computation
![Page 22: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/22.jpg)
Side Note on AlgorithmNamed after a
Persian mathematician “Muhammad ibn Musa Khwarizmi”
Wrote book on linear equation
Introduce number 0
![Page 23: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/23.jpg)
Topics OverviewAnalysis part
![Page 24: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/24.jpg)
Asymptotic NotationMeasurement of “efficiency” of algorithms
How to compare two algorithmsHow to predict behavior of the algorithm
![Page 25: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/25.jpg)
Big O analysisHow to determine Big O of some codeRecurrent Relation
![Page 26: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/26.jpg)
NP-CompleteWhat computer could solve
EfficientlyInefficiently
The difference between “Efficiency” and “Inefficiency”
![Page 27: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/27.jpg)
Topics OverviewSynthesis part
![Page 28: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/28.jpg)
Divide and ConquerSolve a problem instance by dividing into
smaller instanceBased on induction
![Page 29: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/29.jpg)
Dynamic ProgrammingReduce redundancy computationFor the case when there are several
overlapping subproblem
![Page 30: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/30.jpg)
Greedy AlgorithmSolve the problem by doing the best for the
current step
Proof of correctness
![Page 31: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/31.jpg)
Graph AlgorithmAlgorithm related to graph structure
Shortest PathMinimal Spanning Tree
![Page 32: Nattee Niparnan Dept. of Computer Engineering, Chulalongkorn University.](https://reader030.fdocuments.us/reader030/viewer/2022032706/56649dda5503460f94acfc2f/html5/thumbnails/32.jpg)
SearchSolve the problem by enumeration
Systematical enumerationPerformance improvement