990 likes | 1.31k Views
Algorithms Design and its Applications. Introduction. Something about me. 刘晓铭 Home Page: http://sist.sysu.edu.cn/~isslxm Email: isslxm@mail.sysu.edu.cn Office: 信息学院楼 526B. Something about this course. Course homepage: http://sist.sysu.edu.cn/~isslxm/ada/cs2013/index.html
E N D
Algorithms Design and its Applications Introduction
Something about me 刘晓铭 • Home Page: http://sist.sysu.edu.cn/~isslxm • Email: isslxm@mail.sysu.edu.cn • Office: 信息学院楼526B
Something about this course • Course homepage:http://sist.sysu.edu.cn/~isslxm/ada/cs2013/index.html • BBS: http://bbs.sysu.edu.cn/bbsdoc?board=ACMICPC • Office Hours:每周一下午2:00 – 4:00,信息学院楼526B其它时间可邮件预约。
Something about this course • 1. 平时作业:在线编程练习+书面作业http://soj.me/ • 2. 研究型的小Project :选一个问题,编程实现解决这一问题的若干种算法,在不同规模的测试数据上,比较各种算法的性能 • 3. 期末考试:ACM 方式机试, 自动测评
FAQ • Q: 这门课是为了培养参加ACM / ICPC比赛的队员而专门开设的吗? • A: No. Some important topics not included in ICPC • Advanced Algorithm Analysis Techniques • NP-Completeness Proofs • Randomized and Approximation Algorithms • Quantum Algorithms
Boss assigns task: • Given today’s prices of pork, grain, sawdust, … • Given constraints on what constitutes a hotdog. • Make the cheapest hotdog. Everyday industry asks these questions.
Your answer: • Um? Tell me what to code. With more sophisticated software engineering systems,the demand for mundane programmers will diminish.
Your answer: • I learned this great algorithm that will work. Soon all known algorithms will be available in libraries.
Your answer: • I can develop a new algorithm for you. Great thinkers will always be needed.
Course Content • A list of algorithms. • Learn their code. • Trace them until you are convinced that they work. • Implement them. • Worry about details. class InsertionSortAlgorithm extends SortAlgorithm { void sort(int a[]) throws Exception { for (inti = 1; i < a.length; i++) { int j = i; int B = a[i]; while ((j > 0) && (a[j-1] > B)) { a[j] = a[j-1]; j--;} a[j] = B; } }
Course Content • A survey of algorithmic design techniques. • Abstract thinking. • How to develop new algorithms for any problem that may arise.
Study: • Many experienced programmers were asked to code up binary search.
Study: • Many experienced programmers were asked to code up binary search. 80% got it wrong
What did they lack? • Formal proof methods?
What did they lack? • Formal proof methods? Yes, likely Industry is starting to realize that formal methods are important. But even without formal methods …. ?
What did they lack? • Fundamental understanding of the algorithmic design techniques. • Abstract thinking.
Course Content Notations, analogies, and abstractions for developing, thinking about, and describing algorithms so correctness is transparent
A survey of fundamental ideas and algorithmic design techniques For example . . .
Logic Quantifiers Logs and Exps g "b Loves(b,g)"b g Loves(b,g) 2a× 2b = 2a+b2log n = n Time Classifying Functions Time Complexity f(i) = nQ(n) t(n) = Q(n2) Input Size Adding Made Easy Recurrence Relations ∑i=1 f(i). T(n) = a T(n/b) + f(n) Some Math
0 i-1 i T+1 i i 5 km 9 km Iterative Algorithms Loop Invariants <preCond> codeA loop <loop-invariant> exit when <exit Cond> codeB codeC <postCond> One step at a time Code Relay Race
2 8 9 5 8 4 4 6 2 3 5 7 5 6 1 3 2 5 4 8 Dynamic Programing 4 5 3 2
Reduction = • Rudich www.discretemath.com
Read Ahead You are expected to read the lecture notesbefore the lecture. This will facilitate more productive discussionduringclass. Also please proof readassignments & tests.
Be Creative Ask questions. Why is it done this way and not thatway?
Please feel free to ask questions! Help me know what people are not understanding Slow down the slides We do have a lot of material Please don’t shout out answersfor at least 10sec.
What is algorithm? Informally, an algorithm is any well – defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output . --Introduction to Algorithms
Sorting Problem Input: A sequence of n keys a1, a2, …, an. Output: The permutation of the input sequence such that a1’≤a2’≤…≤an’. • An instance (实例):Inpute: <31, 41, 59, 26, 41, 58>Output: <26, 31, 41, 41, 58, 59>
如果对每个输入的实例,算法都能正确的停机,则称该算法是正确的。如果对每个输入的实例,算法都能正确的停机,则称该算法是正确的。 • 不正确的算法对某些输入实例可能根本不停机,也可能以不正确的输出停机。 • 不正确的算法只要错误率可控有时可能是有用的。例如,大素数的判定。
Knuth said Knuth (1968, 1973) has given a list of five properties that are widely accepted as requirements for an algorithm: Finiteness: "An algorithm must always terminate after a finite number of steps ... a very finite number, a reasonable number" Definiteness: "Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case" Input: "...quantities which are given to it initially before the algorithm begins. These inputs are taken from specified sets of objects" Output: "...quantities which have a specified relation to the inputs" Effectiveness: "... all of the operations to be performed in the algorithm must be sufficiently basic that they can in principle be done exactly and in a finite length of time by a man using paper and pencil"
Finally … The word algorithm does not have a generally accepted definition. From wikipedia
Analysis of algorithms • The theoretical study of computer-program performance and resource usage. • What’s more important than performance? • modularity • correctness • maintainability • functionality • robustness • user-friendliness • programmer time • simplicity • extensibility • reliability
为什么学习算法 原因之一:广泛的应用 • Human Genome Project • Internet • Electronic commerce security • Other manufacturing and commercial setting • Etc.
为什么学习算法 原因之二:强大的力量 排序n个项,插入排序,c1n2归并排序,c2n lgn n=1000万 计算机A: 较快,每秒执行百亿条指令,执行插入排序,实现较好,代码需要2n2条指令。 计算机B: 较慢,每秒执行1000万条指令,执行归并排序,实现较差,代码需要50nlgn条指令。 计算机A: 2*(107)2条指令/1010条指令每秒=20000秒 计算机B: 50*107lg107条指令/107条指令每秒=1163秒 计算机B比计算机A还快17倍!
为什么学习算法 不懂算法的悲剧 和大姐姐一起来计算! http://www.bilibili.tv/video/av362069/ http://www.youtube.com/watch?v=Q4gTV4r0zRs来自日本科学未来馆的趣味教育动画,介绍的是一个正方形由“起点(S)”到“终点(G)”会有多少种路线,以及关于大姐姐的催人泪下的故事 分析:http://oeis.org/A007764
为什么学习算法 原因之三:Just for fun!