Transcript Document
Algorithms Course website: http://www.cs.uakron.edu/~zduan/class/435 Leigh Hall 409, 2:15-3:05pm Instructor: Dr. Zhong-Hui Duan Teaching assistant: Vasudha Lankireddy, [email protected] Office hour: TBA (CAS 254) Labs and Tutors Office: 238 CAS Phone: 330-972-6773 E-mail: [email protected] Office Hours: MWF1:00-2:00 or appointment https://www.uakron.edu/computer-science/current-students/lab-hours.dot Course Goals: To learn well-known algorithms as well as the design and analysis of these algorithms. Books Textbook: Algorithms by Dasgupta, et al. An excellent reference: Introduction to Algorithms, 3rd Edition, by T.H. Cormen, C.E. Leiserson, R.L. Rivest, and C. Stein, MIT, 2009. Grading: Two exams (15%, 30%). Programs (30%). Weekly homework problems (10%). neat, clear, precise, formal. Quizzes & class participation (15%). Grading Scale (+/- grades may be assigned at instructor's discretion): A 90-100 B 80-89 C 70-79 D 60-69 F 0-59 Program Submissions All programs will be submitted using Springboard. A drop box will be created for each program. You will also need to submit a printed copy of your source code and a readme file. DO NOT submit programs that are not reasonably correct! To be considered reasonably correct, a program must be completely documented and work correctly for sample data provided with the assignment. Programs failing to meet these minimum standards will be returned ungraded and a 30% penalty assessed. Late points will be added on top of this penalty. Ethics: All programming assignments must be your own work. Duplicate or similar programs/reports, plagiarism, cheating, undue collaboration, or other forms of academic dishonesty will be reported to the Student Disciplinary Office as a violation of the Student Honor Code. Dates and Final Exam Time Last Day: Drop: Jan. 26; Withdraw: Mar. 2, 2015 Final Exam: Given according to the University Final Exam schedule. MWF class : Monday, May 4, 2:30 - 4:30pm Algorithm A procedure for solving a computational problem (ex: sorting a set of integers) in a finite number of steps. More specifically: a step-by-step procedure for solving a problem or accomplishing something (especially using a computer). Solving a Computational Problem Problem definition & specification Algorithm analysis & design specify input, output and constraints devise a correct & efficient algorithm Implementation planning Coding, testing and verification Input Algorithm Output Examples RSA. Quicksort. Data compression. Network flow. Signal processing. Huffman codes. Databases. FFT. Cryptography. Routing Internet packets. Linear programming. Planning, decision-making. What is CS435/535? Learn well-known algorithms and the design and analysis of algorithms. Examine interesting problems. Devise algorithms for solving them. Data structures and core algorithms. Analyze running time of programs. Critical thinking. Project 1 and final project Ch 0: Big-O notation Asymptotic Complexity Running time of an algorithm as a function of input size n for large n. Expressed using only the highest-order term in the expression for the exact running time. Instead of exact running time, say Q(n2). Describes behavior of function in the limit. Written using Asymptotic Notation. Asymptotic Notation Q, O, W, o, w Defined for functions over the natural numbers. Ex: f(n) = Q(n2). Describes how f(n) grows in comparison to n2. Define a set of functions; in practice used to compare two function sizes. The notations (Q, O, W, o, w) describe different rate-ofgrowth relations between the defining function and the defined set of functions. O-notation For function g(n), we define O(g(n)), big-O of n, as the set: O(g(n)) = {f(n) : positive constants c and n0, such that n n0, we have 0 f(n) cg(n) } Intuitively: Set of all functions whose rate of growth is the same as or lower than that of g(n). Technically, f(n) O(g(n)). Older usage, f(n) = O(g(n)). g(n) is an asymptotic upper bound for f(n). Examples O(g(n)) = {f(n) : positive constants c and n0, such that n n0, we have 0 f(n) cg(n) } O(n2) n2 +1 n2 +n 1000n2 +1000n n1.999 n2/log n n2/log log logn W -notation For function g(n), we define W(g(n)), big-Omega of n, as the set: W(g(n)) = {f(n) : positive constants c and n0, such that n n0, we have 0 cg(n) f(n)} Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). g(n) is an asymptotic lower bound for f(n). Example W(g(n)) = {f(n) : positive constants c and n0, such that n n0, we have 0 cg(n) f(n)} n = W(lg n). Choose c and n0. 1000n2 + 1000n 1000n2 − 1000n n3 n2.00001 n2 log log log n n 22 Q-notation For function g(n), we define Q(g(n)), big-Theta of n, as the set: Q(g(n)) = {f(n) : positive constants c1, c2, and n0, such that n n0, we have 0 c1g(n) f(n) c2g(n) } Intuitively: Set of all functions that have the same rate of growth as g(n). g(n) is an asymptotically tight bound for f(n). Example Q(g(n)) = {f(n) : positive constants c1, c2, and n0, such that n n0, 0 c1g(n) f(n) c2g(n)} 10n2 - 3n = Q(n2) To compare orders of growth, look at the leading term. Exercise: Prove that n2/2-3n= Q(n2) Relations Between O, W, Q Exercise 6 n-10 = Ω(n) Example Is 3n3 = Q(n4) ? How about 22n= Q(2n)? How about log2n = Q(log10n)? Relations Between Q, W, O Theorem : For any two functions g(n) and f(n), f(n) = Q(g(n)) iff f(n) = O(g(n)) and f(n) = W(g(n)). i.e., Q(g(n)) = O(g(n)) W(g(n)) f(n) = Q(g(n)) f(n) = O(g(n)). Q(g(n)) O(g(n)). f(n) = Q(g(n)) f(n) = W(g(n)). Q(g(n)) W(g(n)). In practice, asymptotically tight bounds are obtained from asymptotic upper and lower bounds. Comparison of Functions fg ~ ab f (n) = O(g(n)) ~ a b f (n) = W(g(n)) ~ a b f (n) = Q(g(n)) ~ a = b Properties Transitivity f(n) = Q(g(n)) and g(n) = Q(h(n)) f(n) = Q(h(n)) f(n) = O(g(n)) and g(n) = O(h(n)) f(n) = O(h(n)) f(n) = W(g(n)) and g(n) = W(h(n)) f(n) = W(h(n)) f(n) = o (g(n)) and g(n) = o (h(n)) f(n) = o (h(n)) f(n) = w(g(n)) and g(n) = w(h(n)) f(n) = w(h(n)) Reflexivity f(n) = Q(f(n)) f(n) = O(f(n)) f(n) = W(f(n)) Properties Symmetry f(n) = Q(g(n)) iff g(n) = Q(f(n)) Complementarity f(n) = O(g(n)) iff g(n) = W(f(n)) f(n) = o(g(n)) iff g(n) = w((f(n)) Limits lim [f(n) / g(n)] < f(n) O(g(n)) n 0 < lim [f(n) / g(n)] < f(n) Q(g(n)) n 0 < lim [f(n) / g(n)] f(n) W(g(n)) n lim [f(n) / g(n)] undefined can’t say n complexity classes adjective constant logarithmic linear nlogn quadratic cubic exponential exponential etc. Q-notation Q(1) Q(logn) Q(n) Q(nlogn) Q(n2) Q(n3) Q(2n) Q(10n) Fibonacci Numbers Fibonacci Numbers Properties of a relation R={(a,b)} Transitive Reflexive, irreflexive Symmetric, antisymmetric, asymmetric Equivalence relation: reflexive, symmetric, and transitive. Partial order: reflexive, antisymmetric, and transitive. Relations R={(f(n), g(n)) | f(n) = O(g(n))} R={(f(n), g(n)) | f(n) = Ω(g(n))} R={(f(n), g(n)) | f(n) = Θ(g(n))} R={(f(n), g(n)) | f(n) = o(g(n))} R={(f(n), g(n)) | f(n) = ω(g(n))} Exercise Express functions in A in asymptotic notation using functions in B. A 5n2 + 100n B 3n2 + 2 A Q(B) A Q(n2), n2 Q(B) A Q(B) log3(n2) log2(n3) A Q(B) logba = logca / logcb; A = 2logn / log3, B = 3logn, A/B =2/(3log3) nlog24 3log2n A w(B) alog b = blog a; B =3log n=nlog 3; A/B =nlog(4/3) as n A o (B) log2n n1/2 lim ( loga n / nb ) = 0 (here a = 2 , b = 1/2) A o (B) n Ch1