cse101: design and analysis of...
Post on 14-Mar-2021
10 Views
Preview:
TRANSCRIPT
CSE101: Design and Analysis of Algorithms
Ragesh Jaiswal, CSE, UCSD
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Administrative Information
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Administrative Information
Course Instructor:
Ragesh JaiswalOffice: 3130, CSEEmail: rajaiswal@ucsd.edu
Course webpage:http://www.cs.ucsd.edu/~rajaiswal/Winter2020/cse101/.
The discussion sections will be held this week. We will recap.material from the previous courses that will be used in this course.
The first lecture is being conducted by Prof. Russell Impagliazzo.
The detailed administrative information will be discussed in thesecond lecture by the course instructor.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap. of Data Structures and Algorithms
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
What is an algorithm?
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
What is an algorithm?
A step-by-step way of solving a problem.
How do we measure the performance of an algorithm?
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
What is an algorithm?
A step-by-step way of solving a problem.
How do we measure the performance of an algorithm?
Main ideas for performance measurement:
Worst-case analysis: Largest possible running time over allinput instances of a given size n and then see how thisfunction scales with n.Asymptotic order of growth: The worst-case running time for
large n (e.g., T (n) = 5n3 + 3n2 + 2n + 10)
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
What is an algorithm?
A step-by-step way of solving a problem.
How do we measure the performance of an algorithm?Main ideas for performance measurement:
Worst-case analysis: Largest possible running time over all inputinstances of a given size n and then see how this function scaleswith n.Asymptotic order of growth: The worst-case running time for large
n (e.g., T (n) = 5n3 + 3n2 + 2n + 10)
Figure: Plot of n2 and 2n + 2
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
What is an algorithm?
A step-by-step way of solving a problem.
How do we measure the performance of an algorithm?
Main ideas for performance measurement:
Worst-case analysis: Largest possible running time over allinput instances of a given size n and then see how thisfunction scales with n.Asymptotic order of growth: The worst-case running time for
large n (e.g., T (n) = 5n3 + 3n2 + 2n + 10)
Asymptotic order of growth (O,Ω,Θ):
T (n) is O(f (n)) (or T (n) = O(f (n))) iff there exists constantsc > 0, n0 ≥ 0 such that for all n ≥ n0, we have T (n) ≤ c · f (n).
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Recap.
Growth rates:Arrange the following functions in ascending order of growthrate:
n2√log n
nlog n
2log n
n/ log nnn
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Algorithm: A step-by-step way of solving a problem.
Design of Algorithms:
“Algorithm is more of an art than science”However, we will learn some basic tools and techniques thathave evolved over time. These tools and techniques enable youto effectively design and analyse algorithms.
Analysis of Algorithms:
Proof of correctness: An argument that the algorithm workscorrectly for all inputs.Analysis of worst-case running time as a function of the inputsize.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Algorithm: A step-by-step way of solving a problem.
Design of Algorithms:
“Algorithm is more of an art than science”However, we will learn some basic tools and techniques thathave evolved over time. These tools and techniques enable youto effectively design and analyse algorithms.
Analysis of Algorithms:Proof of correctness: An argument that the algorithm workscorrectly for all inputs.
Proof: A valid argument that establishes the truth of amathematical statement.
Analysis of worst-case running time as a function of the inputsize.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Proof: A valid argument that establishes the truth of amathematical statement.
The statements used in a proof can include axioms, definitions,the premises, if any, of the theorem, and previously proventheorems and uses rules of inference to draw conclusions.
A proof technique very commonly used when provingcorrectness of Algorithms is Mathematical Induction.
Definition (Strong Induction)
To prove that P(n) is true for all positive integers, where P(n) is apropositional function, we complete two steps:
Basis step: We show that P(1) is true.
Inductive step: We show that for all k , if P(1),P(2), ...,P(k)are true, then P(k + 1) is true.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Definition (Strong Induction)
To prove that P(n) is true for all positive integers, where P(n) is apropositional function, we complete two steps:
Basis step: We show that P(1) is true.
Inductive step: We show that for all k , if P(1),P(2), ...,P(k)are true, then P(k + 1) is true.
Question: Show that for all n > 0, 1 + 3 + ... + (2n− 1) = n2.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Question: Show that for all n > 0, 1 + 3 + ... + (2n − 1) = n2.
Proof
Let P(n) be the proposition that 1 + 3 + 5 + ... + (2n − 1) equals n2.Basis step: P(1) is true since the summation consists of only a singleterm 1 and 12 = 1.Inductive step: Assume that P(1),P(2), ...,P(k) are true for anyarbitrary integer k . Then we have:
1 + 3 + ... + (2(k + 1) − 1) = 1 + 3 + ... + (2k − 1) + (2k + 1)
= k2 + 2k + 1 (since P(k) is true)
= (k + 1)2
This shows that P(k + 1) is true.Using the principle of Induction, we conclude that P(n) is true for alln > 0.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Algorithm: A step-by-step way of solving a problem.
Design of Algorithms:
“Algorithm is more of an art than science”However, we will learn some basic tools and techniques thathave evolved over time. These tools and techniques enable youto effectively design and analyse algorithms.
Analysis of Algorithms:Proof of correctness: An argument that the algorithm workscorrectly for all inputs.
Proof: A valid argument that establishes the truth of amathematical statement.
Analysis of worst-case running time as a function of the inputsize.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Algorithm Design Techniques
Divide and ConquerGreedy AlgorithmsDynamic ProgrammingNetwork Flows
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
Introduction
Material that will be covered in the course:
Basic graph algorithmsAlgorithm Design Techniques
Divide and ConquerGreedy AlgorithmsDynamic ProgrammingNetwork Flows
Computational intractability
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionDivide and Conquer
Some examples of Divide and Conquer Algorithms:
Binary SearchMedian findingMultiplying numbersMerge sort, quick sort.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionGreedy Algorithms
Problem
Interval scheduling: You have a lecture room and you get nrequests for scheduling lectures. Each request has a start time andan end time. The goal is to maximise the number of lectures.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionDynamic Programming
Problem
Interval scheduling: You have a lecture room and you get nrequests for scheduling lectures. Each request has a start time, anend time, and a price (that you will get in case the lecture isscheduled). The goal is to maximise your earnings.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionNetwork Flows
Problem
Job assignment: There are n people and n jobs. Each person has alist of jobs he/she could possibly do. Find a job assignment sothat:
1 each job is assigned to a different person, and
2 each person is assigned a job from his/her list.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionComputational Intractability
Is it always possible to find a fast algorithm for any problem?
Problem
Given a social network, find the largest subset of people such thatno two people in the subset are friends.
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
IntroductionComputational Intractability
The problem in the previous slide is called the IndependentSet problem and no one knows if it can be solved inpolynomial time (quickly).
There is a whole class of problems to which Independent Setbelongs.
If you solve one problem in this class quickly, then you cansolve all the problems in this class quickly.
You can also win a million dollars!!
We will see techniques of how to show that a new problembelongs to this class:
Why: because then you can say to your boss that the newproblem belongs to the difficult class of problems and even themost brilliant people in the world have not been able to solvethe problem so do not expect me to do it. Also, if I can solvethe problem there is no reason for me to work for you!
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
End
Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms
top related