Join with Campusw code 0881ire Instructors Dr. Ke Chen Office hours: TuTh 2:00pm - 3:00pm Prof. Mingfu Shao Office hours: TBA 1 / 18 Teaching Assistants Ajmain Ahmed (Recitation TA) Irtesam Khan (Head TA) Jiaqi Lin (Assignment TA) Piyush Nagasubramaniam (Recitation TA) Fatemeh Rahbari (Assignment TA) Aaryan Sarnaik (Recitation TA) Abhishek Shringi (Recitation TA) Balaji Udayagiri (Assignment TA) TAs’ office hours TBA. 2 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. 3 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. ▶ Eight recitation sections, all on Wednesday. (No recitation this week.) 3 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. ▶ Eight recitation sections, all on Wednesday. (No recitation this week.) ▶ Biweekly in-lecture quizzes on Canvas : 5%. 3 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. ▶ Eight recitation sections, all on Wednesday. (No recitation this week.) ▶ Biweekly in-lecture quizzes on Canvas : 5%. ▶ Weekly homework: 15%. 3 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. ▶ Eight recitation sections, all on Wednesday. (No recitation this week.) ▶ Biweekly in-lecture quizzes on Canvas : 5%. ▶ Weekly homework: 15%. ▶ Two midterms: 25% each. 3 / 18 Class Organization ▶ Two lecture sections: ▶ 001 - TuTh 12:05pm - 1:20pm, Sparks building 010 ▶ 002 - TuTh 12:05pm - 1:20pm, Zoom: https://psu.zoom.us/j/96876668200 ▶ Same staff, same assignments. Will run as one big course. ▶ Eight recitation sections, all on Wednesday. (No recitation this week.) ▶ Biweekly in-lecture quizzes on Canvas : 5%. ▶ Weekly homework: 15%. ▶ Two midterms: 25% each. ▶ Final exam: 30%. 3 / 18 Textbook Required: Algorithms (Dasgupta, Papadimitriou, and Vazirani), 1st edition, McGraw Hill Education, 2006. 4 / 18 Textbook Required: Algorithms (Dasgupta, Papadimitriou, and Vazirani), 1st edition, McGraw Hill Education, 2006. 4 / 18 Assignments ▶ 15% of course grade. 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . ▶ Submit through Gradescope. 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . ▶ Submit through Gradescope. ▶ You may choose to work in groups of no more than 3 students . 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . ▶ Submit through Gradescope. ▶ You may choose to work in groups of no more than 3 students . ▶ Must be typed , Latex template on Canvas, MS Word is acceptable. 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . ▶ Submit through Gradescope. ▶ You may choose to work in groups of no more than 3 students . ▶ Must be typed , Latex template on Canvas, MS Word is acceptable. ▶ Two lowest homework scores will be dropped. 5 / 18 Assignments ▶ 15% of course grade. ▶ Post on Friday, due the following Friday at 11:59pm . ▶ Submit through Gradescope. ▶ You may choose to work in groups of no more than 3 students . ▶ Must be typed , Latex template on Canvas, MS Word is acceptable. ▶ Two lowest homework scores will be dropped. ▶ Check the syllabus for other important details. 5 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : 6 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : ▶ Midterm 1: Feb. 19 (Thursday) 8:00pm - 10:00pm 6 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : ▶ Midterm 1: Feb. 19 (Thursday) 8:00pm - 10:00pm ▶ Midterm 2: Apr. 07 (Tuesday) 8:00pm - 10:00pm 6 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : ▶ Midterm 1: Feb. 19 (Thursday) 8:00pm - 10:00pm ▶ Midterm 2: Apr. 07 (Tuesday) 8:00pm - 10:00pm ▶ Classroom assignment TBA. 6 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : ▶ Midterm 1: Feb. 19 (Thursday) 8:00pm - 10:00pm ▶ Midterm 2: Apr. 07 (Tuesday) 8:00pm - 10:00pm ▶ Classroom assignment TBA. ▶ Midterms are non-cumulative. 6 / 18 Midterms ▶ Both midterms are scheduled as 2-hour evening exams : ▶ Midterm 1: Feb. 19 (Thursday) 8:00pm - 10:00pm ▶ Midterm 2: Apr. 07 (Tuesday) 8:00pm - 10:00pm ▶ Classroom assignment TBA. ▶ Midterms are non-cumulative. ▶ Closed book, closed notes. 6 / 18 Getting Help QA ▶ Homework questions? Campuswire ▶ Course logistics? Campuswire and your recitation’s TA ▶ Questions that may be of interest to other students? Campuswire ▶ Re-grade requests? Gradescope ▶ Contacting the instructors? Campuswire or office hours Email responses from the instructors may be slow due to the size of the class ▶ Instructors’ office hours: For major concerns and high-level questions. ▶ TAs’ office hours: You are welcome to attend any/all. 7 / 18 CMPSC 465: LECTURE I Introduction to Algorithm Analysis Ke Chen Janurary 13, 2026 Why study algorithms? ▶ Computation is fundamental to understanding the world . ▶ social networks, brains, black holes, evolution, ... 9 / 18 Why study algorithms? ▶ Computation is fundamental to understanding the world . ▶ social networks, brains, black holes, evolution, ... ▶ Analyze correctness and resource usage . 9 / 18 Why study algorithms? ▶ Computation is fundamental to understanding the world . ▶ social networks, brains, black holes, evolution, ... ▶ Analyze correctness and resource usage . ▶ Measure feasibility (what can and cannot be done efficiently). ▶ NP-completeness 9 / 18 Why study algorithms? ▶ Computation is fundamental to understanding the world . ▶ social networks, brains, black holes, evolution, ... ▶ Analyze correctness and resource usage . ▶ Measure feasibility (what can and cannot be done efficiently). ▶ NP-completeness ▶ Interviews! 9 / 18 Why study algorithms? ▶ Computation is fundamental to understanding the world . ▶ social networks, brains, black holes, evolution, ... ▶ Analyze correctness and resource usage . ▶ Measure feasibility (what can and cannot be done efficiently). ▶ NP-completeness ▶ Interviews! ▶ Lots of FUN! 9 / 18 What is an algorithm? Algorithm : Finite set of unambiguous, step-by-step instructions to solve a problem. You already know many algorithms! 10 / 18 What is an algorithm? Algorithm : Finite set of unambiguous, step-by-step instructions to solve a problem. You already know many algorithms! ▶ Addition, subtraction, multiplication, and division. ▶ Making change with cash. ▶ Sorting socks out of your laundry basket. 10 / 18 What is an algorithm? Algorithm : Finite set of unambiguous, step-by-step instructions to solve a problem. You already know many algorithms! Defant and Kravitz, Foot-sorting for socks, arXiv, 2022 10 / 18 Algorithm analysis Three questions will drive us. 11 / 18 Algorithm analysis Three questions will drive us. ▶ Correctness : Does the algorithm work every time? 11 / 18 Algorithm analysis Three questions will drive us. ▶ Correctness : Does the algorithm work every time? ▶ Complexity : Is it efficient? ( Time and Space ) 11 / 18 Algorithm analysis Three questions will drive us. ▶ Correctness : Does the algorithm work every time? ▶ Complexity : Is it efficient? ( Time and Space ) ▶ Can we do better? 11 / 18 Algorithm analysis Three questions will drive us. ▶ Correctness : Does the algorithm work every time? ▶ Complexity : Is it efficient? ( Time and Space ) ▶ Can we do better? Other important considerations: robustness, energy efficiency, cache locality, modularity, maintenance time, etc. are beyond the scope of this course. 11 / 18 A simple example: LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found LinearSearch(A, k) i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 12 / 18 A simple example: LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found LinearSearch(A, k) i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 Correctness? 12 / 18 A simple example: LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found LinearSearch(A, k) i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 Correctness? Easy! Examine each element until the key is found, or the array has been exhausted. 12 / 18 A simple example: LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found LinearSearch(A, k) i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 Correctness? Easy! Examine each element until the key is found, or the array has been exhausted. Time complexity? 12 / 18 How to measure time complexity? Several issues: ▶ Running time may depend on input size . ▶ Running time can be different for different inputs . ▶ Running time fluctuates with implementation/hardware . 13 / 18 How to measure time complexity? Issue 1: Running time may depend on input size. Idea: Parameterize running time by the size of the input, T (n) . 14 / 18 How to measure time complexity? Issue 1: Running time may depend on input size. Idea: Parameterize running time by the size of the input, T (n) . Issue 2: Running time can be different for different inputs. 14 / 18 How to measure time complexity? Issue 1: Running time may depend on input size. Idea: Parameterize running time by the size of the input, T (n) . Issue 2: Running time can be different for different inputs. Worst-case analysis: (usually) ▶ T (n) = maximum time of algorithm on ANY input of size n . Average-case: (sometimes) ▶ T (n) = expected time of algorithm over all inputs of size n. ▶ Requires assumption on input distribution. Amortized: (sometimes) ▶ T (m) = total time over m calls / m. Best-case: (never) ▶ Cheat with a slow algorithm that works well on some inputs. 14 / 18 How to measure running time? Issue 3: Running time may depend on implementation/hardware. Idea: Give up on gauging the actual time and focus on scalability by considering a simplified abstract computing model: ▶ single processor, sequential execution ▶ elementary operations take constant time ▶ addition, subtraction ▶ multiplication, division ▶ assignment, branching ▶ subroutine call ▶ etc. 15 / 18 How to measure running time? Issue 3: Running time may depend on implementation/hardware. Idea: Give up on gauging the actual time and focus on scalability by considering a simplified abstract computing model: ▶ single processor, sequential execution ▶ elementary operations take constant time ▶ addition, subtraction ▶ multiplication, division ▶ assignment, branching ▶ subroutine call ▶ etc. Warning: we assume operands are of constant size irrelevant to the input size n (see book chapter 1). 15 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) 3µs 1 i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do n (worst-case) c3 if A[i] == k then return i i=i−1 return −1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do n (worst-case) c3 if A[i] == k then c4 return i 1 n (worst-case) c5 i=i−1 return −1 c4 1 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do n (worst-case) c3 if A[i] == k then c4 return i 1 n (worst-case) c5 i=i−1 return −1 c4 1 Worst-case running time: T (n) = c1 + c2 n + c3 n + c4 + c5 n = (c2 + c3 + c5 )n + c1 + c4 . 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do n (worst-case) c3 if A[i] == k then c4 return i 1 n (worst-case) c5 i=i−1 return −1 c4 1 Worst-case running time: T (n) = c1 + c2 n + c3 n + c4 + c5 n = (c2 + c3 + c5 )n + c1 + c4 . a b 16 / 18 Time complexity of LinearSearch Input: An array A of size n, a key k to search for Output: Last index of k in A, −1 if not found Cost Rounds LinearSearch(A, k) c 1 1 i=n−1 c2 n (worst-case) while i ≥ 0 do n (worst-case) c3 if A[i] == k then c4 return i 1 n (worst-case) c5 i=i−1 return −1 c4 1 Worst-case running time: T (n) = c1 + c2 n + c3 n + c4 + c5 n = (c2 + c3 + c5 )n + c1 + c4 . an + b, linear a b 16 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → ▶ 100× time? E.g. T (n) = 0.3n2 → ▶ 1000× time? E.g. T (n) = 82n3 → ▶ much much longer? E.g. T (n) = 2n → 17 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → T (10n) = 150n (linear) ▶ 100× time? E.g. T (n) = 0.3n2 → ▶ 1000× time? E.g. T (n) = 82n3 → ▶ much much longer? E.g. T (n) = 2n → 17 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → T (10n) = 150n (linear) ▶ 100× time? E.g. T (n) = 0.3n2 → T (10n) = 30n2 (quadratic) ▶ 1000× time? E.g. T (n) = 82n3 → ▶ much much longer? E.g. T (n) = 2n → 17 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → T (10n) = 150n (linear) ▶ 100× time? E.g. T (n) = 0.3n2 → T (10n) = 30n2 (quadratic) ▶ 1000× time? E.g. T (n) = 82n3 → T (10n) = 82000n3 (cubic) ▶ much much longer? E.g. T (n) = 2n → 17 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → T (10n) = 150n (linear) ▶ 100× time? E.g. T (n) = 0.3n2 → T (10n) = 30n2 (quadratic) ▶ 1000× time? E.g. T (n) = 82n3 → T (10n) = 82000n3 (cubic) ▶ much much longer? E.g. T (n) = 2n → T (10n) = 210n = 1024n (exponential) 17 / 18 How to measure running time? Scalability: If the input size becomes 10× larger , will the algorithm take ▶ the same time? E.g. T (n) = 42 → T (10n) = 42 (constant) ▶ 10× time? E.g. T (n) = 15n → T (10n) = 150n (linear) ▶ 100× time? E.g. T (n) = 0.3n2 → T (10n) = 30n2 (quadratic) ▶ 1000× time? E.g. T (n) = 82n3 → T (10n) = 82000n3 (cubic) ▶ much much longer? E.g. T (n) = 2n → T (10n) = 210n = 1024n (exponential) How about the running time for LinearSearch T (n) = an + b ? 17 / 18 Asymptotic notation For T (n) = an + b, when n approaches infinity, we have T (10n) 10an + b = lim = 10. n→∞ T (n) n→∞ an + b lim So, asymptotically, it has the same scaling behavior as f (n) = 15n. 18 / 18 Asymptotic notation For T (n) = an + b, when n approaches infinity, we have T (10n) 10an + b = lim = 10. n→∞ T (n) n→∞ an + b lim So, asymptotically, it has the same scaling behavior as f (n) = 15n. And they both grow much slower than g(n) = 0.3n2 , even though for small n : f (1) = 15 > g(1) = 0.3. 18 / 18 Asymptotic notation For T (n) = an + b, when n approaches infinity, we have T (10n) 10an + b = lim = 10. n→∞ T (n) n→∞ an + b lim So, asymptotically, it has the same scaling behavior as f (n) = 15n. And they both grow much slower than g(n) = 0.3n2 , even though for small n : f (1) = 15 > g(1) = 0.3. Definition: big-O For two functions f, g : N → R+ , we say f = O(g) if there exist c > 0 and n0 ∈ N such that f (n) ≤ c · g(n) for all n ≥ n0 . 18 / 18 Asymptotic notation For T (n) = an + b, when n approaches infinity, we have T (10n) 10an + b = lim = 10. n→∞ T (n) n→∞ an + b lim So, asymptotically, it has the same scaling behavior as f (n) = 15n. And they both grow much slower than g(n) = 0.3n2 , even though for small n : f (1) = 15 > g(1) = 0.3. Definition: big-O For two functions f, g : N → R+ , we say f = O(g) if there exist c > 0 and n0 ∈ N such that f (n) ≤ c · g(n) for all n ≥ n0 . Example: 15n = O(n) because we can choose c = 20, n0 = 1. 18 / 18
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )