Presented by Po-Chuan & Chen-Chen 2016/03/08

Slides:



Advertisements
Similar presentations
1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Advertisements

CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Greedy Algorithms.
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
Analysis of Algorithms
Instructor Neelima Gupta Table of Contents Greedy Algorithms.
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Lecture 7: Greedy Algorithms II Shang-Hua Teng. Greedy algorithms A greedy algorithm always makes the choice that looks best at the moment –My everyday.
Greedy Algorithms Reading Material: –Alsuwaiyel’s Book: Section 8.1 –CLR Book (2 nd Edition): Section 16.1.
Greedy Algorithms CIS 606 Spring Greedy Algorithms Similar to dynamic programming. Used for optimization problems. Idea – When we have a choice.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
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.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
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.
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lecture 8 CSE 331. Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis.
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
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.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 3.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
6/13/20161 Greedy A Comparison. 6/13/20162 Greedy Solves an optimization problem: the solution is “best” in some sense. Greedy Strategy: –At each decision.
PREPARED BY: Qurat Ul Ain SUBMITTED TO: Ma’am Samreen.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Greedy Algorithms General principle of greedy algorithm
Greedy algorithms: CSC317
Greedy Algorithms.
Greedy Algorithms – Chapter 5
Lecture on Design and Analysis of Computer Algorithm
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Greedy Algorithms (Chap. 16)
Design & Analysis of Algorithm Greedy Algorithm
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Chapter 4 Greedy Algorithms
Greedy Algorithms / Interval Scheduling Yin Tat Lee
ICS 353: Design and Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Chapter 16: Greedy algorithms Ming-Te Chi
Hannah Tang and Brian Tjaden Summer Quarter 2002
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Lecture 6 Topics Greedy Algorithm
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Lecture 19 CSE 331 Oct 8, 2014.
Chapter 16: Greedy algorithms Ming-Te Chi
Richard Anderson Autumn 2016 Lecture 7
Lecture 18 CSE 331 Oct 9, 2017.
Richard Anderson Lecture 7 Greedy Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Greedy Algorithms Comp 122, Spring 2004.
Richard Anderson Winter 2019 Lecture 7
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Week 2: Greedy Algorithms
Greedy algorithms.
Richard Anderson Autumn 2015 Lecture 7
Analysis of Algorithms CS 477/677
Minimum-Cost Spanning Tree
Richard Anderson Autumn 2019 Lecture 7
Presentation transcript:

Presented by Po-Chuan & Chen-Chen 2016/03/08 Greedy algorithms Presented by Po-Chuan & Chen-Chen 2016/03/08

Outline Interval scheduling: The greedy algorithm stays ahead Scheduling to minimize lateness: An exchange argument Shortest paths The minimum spanning tree problem Implementing Kruskal’s algorithm: Union-find

Greedy Algorithms When we have a choice to make, make the one that looks best right now. Make a locally optimal choice in hope of getting a globally optimal solution . It’s easy to invent greedy algorithms for almost any problem. Intuitive and fast Usually not optimal It’s challenging to prove greedy algorithms succeed in solving a nontrivial problem optimally. The greedy algorithm stays ahead. An exchange argument.

Interval Scheduling Given: Set of requests {1, 2, ..., n}, request corresponds an interval with start time s(i) and finish time f(i) interval i: [s(i), f(i)) Goal: Find a compatible subset of the requests with maximum size

Greedy Rules Repeat Until run out of requests. Use a simple rule to select a first request i1 . Once i1 is selected, reject all requests not compatible with i1. Until run out of requests. The rule we use here is selecting the activity that doesn’t overlap with chosen activities and finish earliest. Therefore, sort the activities by finish time, in ascending order first.

Pseudo Code

The Greedy Algorithm Stays Ahead We will compare the partial solutions of A and O, and show that the greedy algorithm is doing better in a step-by-step fashion. Let A be the output of the greedy algorithm, A = { i1, ..., ik }, in the order they were added. Let O be the optimal solution, O = { j1 ,..., jm } in the ascending order of start (finish) times. For all indices 𝑟≤𝑘, we have 𝑓 𝑖 𝑟 ≤𝑓( 𝑗 𝑟 )

The Proof When 𝑛=1, the proposition holds. Suppose the proposition holds when 𝑛=𝑘−1: 𝑓 𝑖 𝑟−1 ≤𝑓( 𝑗 𝑟−1 ) Prove that the proposition holds when 𝑛=𝑘: O is compatible 𝑓 𝑗 𝑟−1 ≤𝑠 𝑗 𝑟 →𝑓 𝑖 𝑟−1 ≤𝑠( 𝑗 𝑟 ) We can select 𝑗 𝑟 as 𝑖 𝑟 𝑓 𝑖 𝑟 ≤𝑠( 𝑗 𝑟 ) Therefore the proposition holds.

The Greedy Algorithm Is Optimal Pf: Proof by contradiction. If A is not optimal, then an optimal set O must have more requests. Since 𝑓 𝑖 𝑘 ≤𝑓 𝑗 𝑘 and 𝑚>𝑘, there is a request 𝑗 𝑘+1 in O. 𝑓 𝑖 𝑘 ≤𝑓 𝑗 𝑘 ≤𝑠 𝑗 𝑘+1 Hence, 𝑗 𝑘+1 is compatible with 𝑖 𝑘 . R should contain 𝑗 𝑘+1 . However, the greedy algorithm stops with request 𝑖 𝑘 , and it is only supposed to stop when R is empty. →←

What if We Have Multiple Resources? Partition these requests into a minimum number of compatible subsets, each corresponds to one resource.

What if We Have Multiple Resources? The depth of a set of intervals is the maximum number that pass over any single point on the time-line. The depth (𝑑) is the answer.

Pseudo Code Assign a label to each interval. Possible labels: {1, 2, …, 𝑑}. Assign different labels for overlapping intervals. Interval-Partitioning(R) {𝐼1, …, 𝐼𝑛} = intervals sort by start times (ascending) for j from 1 to n do exclude labels not compatible with 𝐼𝑗 if there is a non-excluded label assign this label to 𝐼𝑗 else leave 𝐼𝑗 unlabeled

Proof No interval ends up unlabeled. Suppose interval 𝐼𝑗 overlaps 𝑡 intervals earlier in the sorted list. These 𝑡+1 intervals pass over a common point, 𝑠(𝐼𝑗). Hence, 𝑡+1≤𝑑. Thus, 𝑡≤𝑑–1; at least one of the 𝑑 labels is not excluded, and so there is a label that can be assigned to 𝐼𝑗. Line 6 never occurs!

Proof No two overlapping intervals are assigned with the same label. Consider any two intervals 𝐼𝑖 and 𝐼𝑗 that overlap, 𝑖<𝑗. When 𝐼𝑗 is considered (in line 2), 𝐼𝑖 is in the set of intervals whose labels are excluded (in line 3). Hence, the algorithm will not assign 𝐼𝑗 the label used for 𝐼𝑖. Since the algorithm uses 𝑑 labels, we can conclude that the greedy algorithm always uses the minimum possible number of labels, i.e., it is optimal!