Lecture 8 CSE 331. Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis.

Slides:



Advertisements
Similar presentations
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Advertisements

Lecture 28 CSE 331 Nov 9, Flu and HW 6 Graded HW 6 at the END of the lecture If you have the flu, please stay home Contact me BEFORE you miss a.
Lecture 21 CSE 331 Oct 20, Announcements Graded mid-term exams at the END of the lecture Sign up for blog posts/group scribe leader No more than.
Lecture 33 CSE 331 Nov 20, Homeworks Submit HW 9 by 1:10PM HW 8 solutions at the end of the lecture.
Lecture 23 CSE 331 Oct 24, Temp letter grades assigned See the blog post for more details.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
Lecture 34 CSE 331 Nov 30, Graded HW 8 On Wednesday.
Lecture 37 CSE 331 Dec 1, A new grading proposal Towards your final score in the course MAX ( mid-term as 25%+ finals as 40%, finals as 65%) .
Lecture 24 CSE 331 Oct 27, Online office hours tonight 9:00pm.
Lecture 20 CSE 331 Oct 21, Algorithm for Interval Scheduling R: set of requests Set A to be the empty set While R is not empty Choose i in R with.
Lecture 30 CSE 331 Nov 10, Online Office Hours
9/3/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Guest lecturer: Martin Furer Algorithm Design and Analysis L ECTURE.
Called as the Interval Scheduling Problem. A simpler version of a class of scheduling problems. – Can add weights. – Can add multiple resources – Can ask.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 8.
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Greedy Algorithms Interval Scheduling and Fractional Knapsack These slides are based on the Lecture Notes by David Mount for the course CMSC 451 at the.
Lecture 18 CSE 331 Oct 12, HW 5 due today Q1, Q2 and Q3 in different piles I will not take any HW after 1:15pm.
Lecture 18 CSE 331 Oct 6, Group/Algo registration deadline BOTH DUE WED by 11:59pm!
Lecture 33 CSE 331 Nov 20, HW 8 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm Submit your HWs to the side of.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Lecture 9 CSE 331 June 18, The “real” end of Semester blues MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term.
Greedy algorithms: CSC317
Lecture 32 CSE 331 Nov 16, 2016.
Lecture 31 CSE 331 Nov 14, 2016.
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Lecture 16 CSE 331 Oct 5, 2016.
Lecture 17 CSE 331 Oct 3, 2014.
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Lecture 31 CSE 331 Nov 13, 2017.
Lecture 34 CSE 331 Nov 26, 2012.
Lecture 22 CSE 331 Oct 22, 2010.
Lecture 34 CSE 331 Nov 26, 2012.
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Lecture 20 CSE 331 Oct 14, 2016.
Lecture 17 CSE 331 Oct 7, 2016.
Lecture 26 CSE 331 Nov 1, 2017.
Lecture 19 CSE 331 Oct 12, 2016.
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Lecture 16 CSE 331 Oct 4, 2017.
Richard Anderson Lecture 6 Greedy Algorithms
Lecture 18 CSE 331 Oct 12, 2011.
Lecture 19 CSE 331 Oct 8, 2014.
Lecture 20 CSE 331 Oct 17, 2011.
Lecture 32 CSE 331 Nov 15, 2017.
Lecture 33 CSE 331 Nov 14, 2014.
Lecture 27 CSE 331 Oct 31, 2014.
Richard Anderson Autumn 2016 Lecture 7
Lecture 33 CSE 331 Nov 15, 2013.
Lecture 34 CSE 331 Nov 18, 2011.
Lecture 28 CSE 331 Nov 7, 2012.
Lecture 27 CSE 331 Nov 2, 2010.
Lecture 18 CSE 331 Oct 9, 2017.
Richard Anderson Lecture 7 Greedy Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Lecture 20 CSE 331 Oct 13, 2017.
Lecture 19 CSE 331 Oct 14, 2011.
Lecture 21 CSE 331 Oct 19, 2011.
Lecture 21 CSE 331 Oct 22, 2012.
Lecture 36 CSE 331 Nov 30, 2012.
Richard Anderson Winter 2019 Lecture 7
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Week 2: Greedy Algorithms
Lecture 19 CSE 331 Oct 10, 2016.
Lecture 32 CSE 331 Nov 12, 2014.
Richard Anderson Autumn 2015 Lecture 7
Lecture 27 CSE 331 Nov 1, 2013.
Richard Anderson Autumn 2019 Lecture 7
Presentation transcript:

Lecture 8 CSE 331

Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis Data Structures

Where do graphs fit in? Problem Statement Algorithm Problem Definition Implementation Analysis A tool to define problems

Rest of the course Problem Statement Algorithm Problem Definition Implementation Analysis Three general techniques Now: Greedy Algorithms Later: Divide and Conquer Later: Dynamic Programming

Greedy algorithms Build the final solution piece by piece Being short sighted on each piece Never undo a decision

End of Semester blues MondayTuesdayWednesdayThursdayFriday Project 331 homework 331 HW Exam study Party! Write up a term paper Can only do one thing at any day: what is the maximum number of tasks that you can do?

Greedily solve your blues! MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term paper Arrange tasks in some order and iteratively pick non- overlapping tasks

Ordering is crucial MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term paper Order by starting time Algo =1

Another attempt MondayTuesdayWednesdayThursdayFriday Order by duration Algo =1 Ordering by least conflicts doesn’t work

The final algorithm MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term paper Order tasks by their END time

Today’s agenda Prove the correctness of the algorithm

Formal Algorithm R: set of requests Set A to be the empty set While R is not empty Choose i in R with the earliest finish time Add i to A Remove all requests that conflict with i from R Return A

Algorithm for Interval Scheduling R: set of requests Set A to be the empty set While R is not empty Choose i in R with the earliest finish time Add i to A Remove all requests that conflict with i from R Return A A is optimal

Run time analysis Set A to be the empty set While R is not empty Choose i in R with the earliest finish time Add i to A Remove all requests that conflict with i from R Return A O(n log n) time sort intervals such that f(i) ≤ f(i+1) O(n) time to iterate over all the intervals Do the removal on the fly

Algorithm implementation Go through the intervals in order of their finish time How can you tell in O(1) time if any of 2,3 or 4 conflict with 1? Check if s[i] < f(1) In general, if jth interval is the last one chosen Pick smallest i>j such that s[i] ≥ f(j) O(n log n) run time

The final algo Add 1 to A and set f = f(1) For i = 2.. n If s[i] ≥ f Add i to A Set f = f(i) Return A O(n log n) time sort intervals such that f(i) ≤ f(i+1) O(n) time to iterate over all the intervals

Proof of correctness “greedy stays ahead”