cse 202: design and analysis of algorithms · an example what is the shortest route from san...

32
CSE 202: Design and Analysis of Algorithms Lecture 1

Upload: lamphuc

Post on 30-Jul-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

CSE 202: Design and Analysis of Algorithms

!

Lecture 1 !

Page 2: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Logistics

• Instructor: Kamalika Chaudhuri (kamalika@cs)

• Office Hours: F 10:30-11:30am, 4110 EBU3B

• TAs: Chicheng Zhang(chz038@eng), Joseph Geumlek(jgeumlek@cs)

• Office Hours: TBA

• http://cseweb.ucsd.edu/classes/sp16/cse202-a/

Page 3: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Algorithms

Problem Abstraction Algorithm

Page 4: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

An Example

What is the shortest route from San Francisco to San Diego ?

Abstraction:

Problem:

Weighted Graph GNode: CityEdge: Joins two citiesEdge weight: Distance between cities

What is the shortest path between San Francisco and San Diego in G?

Page 5: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

An Example

What is the shortest route from San Francisco to San Diego ?

Abstraction:

Problem:

Shortest path in a graph

Algorithm:Exhaustive Search, Dijkstra’s Algorithm, etc.

Page 6: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Algorithm Design Issues

• Correctness

• Efficiency

Page 7: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Algorithm Design Issues: Correctness

• Recall: Shortest Path problem in a graph

• Does the algorithm always provide a shortest path?

Page 8: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Algorithm Design Issues: Efficiency

• Recall: Shortest Path problem in a graph

• Algorithm 1: Iterate over all paths from SD to SF, and find the one with minimum weight.

• Is this a good algorithm?

• No! Can take exponential(v) time

• Dijkstra’s algorithm takes O(e + vlog v) time

Page 9: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Summary

• In this class, you will learn to:

• Create abstractions from problems

• Design algorithms for abstracted problems

!

• Algorithm design issues we will look at:

• Correctness

• Efficiency

Page 10: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Administrivia

Page 11: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Prerequisites

• Mathematical class

• CSE 101 or equivalent

• Calibration Quiz Friday Apr 1 in class

• Will cover Big O notation, Recurrences, Basic graph search, Dijkstra’s algorithm

• Calibration Quiz will not count towards grade

Page 12: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Textbook

• Algorithm Design, by Jon Kleinberg, and Eva Tardos

Page 13: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Syllabus

• Chapters1-3: Read on your own (tested in calibration quiz)

• Chapter 4: Greedy

• Chapter 6: Dynamic Programming

• Chapter 7: Network Flows

• Chapter 13: Randomized Algorithms

Page 14: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Assessment

• Homeworks (25%)

• Midterm (in-class) (35%)

• Final (in class) (35%)

• Class Participation (5%)

• Calibration quiz (0%)

Page 15: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Midterm and Final

• Midterm - in-class on Wed May 11

• Final - Jun 9 at 11:30am-1pm

!

• If you cannot make these dates, please do not take the class. We will only make exceptions for medical emergencies.

Page 16: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Homework Policy

• Homeworks are due in class at the beginning of lecture

• No late homeworks will be accepted!

Page 17: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Collaboration Policy

• Homeworks should be done in groups of one or two or three

• Email me the name of your group members by Fri Apr 8

• If you need a group member, please post on Piazza group for the class

Page 18: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Collaboration Policy

!

• You must not look for solutions to homework problems on the internet

• If you happen to see a homework solution somewhere, please acknowledge the source!

Page 19: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Collaboration Policy

• If someone (except me or TA) helps you with your homework, acknowledge the source!

• Remember: Academic dishonesty is taken very seriously!

• More details on this on the class website

Page 20: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Class Participation

• Participation in In-class Problem Sessions

• Participation on Piazza

• Top 10 answerers on Piazza will get 5%

Page 21: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Grading Policy

!

• Be clear and unambiguous (but no code)

• Have a proof of correctness

• Have a running time analysis

• Be relatively efficient

Any algorithm you present must:

Page 22: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Grading Policy: Clarity!

• Proofs will be graded by correctness and clarity

• Your arguments should be clear and precise

• More partial credit for clearly written partial solution than attempt to cover up holes in your argument

• Sample solutions on class website

• We’ll look at some examples in class

Page 23: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Algorithm Design Paradigms

Page 24: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 1: Exhaustive Search

• Usually computationally inefficient

• May be useful for some small problems

Page 25: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 2: Greedy Algorithms

• Build the solution piece by piece

• Examples: Dijkstra’s algorithm, Kruskal

• Does not always work correctly!

Page 26: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 3: Divide and Conquer

• Divide the problem into smaller subproblems

• Solve each subproblem

• Combine the results

• Example: Mergesort

Page 27: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 4: Dynamic Programming

• Define a proper notion of subtask

• Solve the subtasks by size

• Once smaller subtasks are solved, larger ones are easy

• Example: computing the edit distance

Page 28: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 5: Hill-climbing

• Start with any solution

• Improve the solution by tweaking it a little

• Continue until optimality

• Example: Flows, linear programming

Page 29: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Paradigm 6: Randomized Algorithms

• Use some randomness in the algorithm to get out of bad situations

• Usually very simple and efficient

• May not always succeed, but works with high probability

• Example: min-cut, MAX-SAT

Page 30: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Intractable Problems

• No efficient solution possible, provably!

• A way out is to find a good approximate solution

Page 31: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Summary: Algorithm Design Paradigms

• Exhaustive Search

• Greedy Algorithms: Build a solution incrementally

• Divide and Conquer: Divide into parts, solve each part, combine results

• Dynamic Programming: Divide into subtasks, perform subtask by size. Combine smaller subtasks to larger ones

• Hill-climbing: Start with a solution, improve it

• Randomized: Use some randomness

Page 32: CSE 202: Design and Analysis of Algorithms · An Example What is the shortest route from San Francisco to San Diego ? Abstraction: Problem: Shortest path in a graph Algorithm:

Announcement

• Email me the name of your group members by Fri Apr 8

• No lecture on Wed Mar 30

• Calibration Quiz in class on Fri Apr 1

• Covers Big O, recurrences, basic graph algorithms (BFS/DFS), Dijkstra’s algorithm

• TA OH will be posted on Piazza