cse101: design and analysis of algorithmscseweb.ucsd.edu/.../cse101/slides/week-01/lec-2.pdf2...

21
CSE101: Design and Analysis of Algorithms Ragesh Jaiswal, CSE, UCSD Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Upload: others

Post on 02-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

CSE101: Design and Analysis of Algorithms

Ragesh Jaiswal, CSE, UCSD

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 2: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Administrative Information

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 3: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Administrative Information

Course Instructor:

Ragesh JaiswalOffice: 3130, CSEEmail: [email protected]

Office hours: 4-5, Tuesday

Course Time/Place: Information on the course page.

Teaching Assistants: Information on the course page.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 4: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Administrative Information

Grading Scheme1 Homework: 15%2 Quizzes: 15%3 Midterms: 30% (2 midterms, 15% each)4 Final: 40%

Homework and Quizzes:

Homework will be posted every Friday by 7pm and will be duethe following Thursday at 10pm. Late submissions will not beallowed since the solutions will be posted on the course pagesoon after the deadline.There will be a quiz every Friday on the material of thehomework submitted on Thursday.You will have to upload the PDF of your homework onGradescope.

Policy on cheating: Students using unfair means will beseverely penalised.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 5: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Administrative Information

Gradescope: A paperless grading system. Use the course code9DYYKE to register in the course on Gradescope. Use onlyyour @ucsd email address to register on Gradescope.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 6: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Administrative Information

Textbook: Algorithm Design by Jon Kleinberg and EvaTardos.

I will be following this book very closely. So, it will be a goodidea to get a copy of this book.

Other reference books:

Algorithms by Sanjoy Dasgputa, Christos Papadimitriou, andUmesh Vazirani.Introduction to Algorithms by Thomas H. Cormen, Charles E.Leiserson Ronald L. Rivest, and Cliff Stein.

Course webpage:http://www.cs.ucsd.edu/~rajaiswal/Winter2020/cse101/.

The site will contain course information, references, homework,course slides etc. Please check this page regularly.

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 7: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Introduction

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 8: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 9: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 10: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 11: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 12: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 13: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

Introduction

Algorithm Design Techniques

Divide and ConquerGreedy AlgorithmsDynamic ProgrammingNetwork Flows

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms

Page 14: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 15: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 16: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 17: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 18: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 19: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 20: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

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

Page 21: CSE101: Design and Analysis of Algorithmscseweb.ucsd.edu/.../cse101/Slides/Week-01/lec-2.pdf2 Quizzes: 15% 3 Midterms: 30% (2 midterms, 15% each) 4 Final: 40% Homework and Quizzes:

End

Ragesh Jaiswal, CSE, UCSD CSE101: Design and Analysis of Algorithms