CS4335 Design and Analysis of Algorithms/WANG Lusheng

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Algorithm Design Methods Spring 2007 CSE, POSTECH.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Analysis of Algorithms
Greed is good. (Some of the time)
Cs333/cutler Greedy1 Introduction to Greedy Algorithms The greedy technique Problems explored –The coin changing problem –Activity selection.
Lecture 3: Greedy Method Greedy Matching Coin Changing Minimum Spanning Tree Fractional Knapsack Dijkstra's Single-Source Shortest-Path.
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.
0-1 Knapsack Problem A burglar breaks into a museum and finds “n” items Let v_i denote the value of ith item, and let w_i denote the weight of the ith.
Greedy Algorithms CIS 606 Spring Greedy Algorithms Similar to dynamic programming. Used for optimization problems. Idea – When we have a choice.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
 2004 SDU Lecture 6- Minimum Spanning Tree 1.The Minimum Spanning Tree Problem 2.Greedy algorithms 3.A Generic Algorithm 4.Kruskal’s Algorithm.
Algorithm Design Methods 황승원 Fall 2011 CSE, POSTECH.
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.
Greedy Algorithms Chapter 16 Highlights
CS 361 – Chapter 10 “Greedy algorithms” It’s a strategy of solving some problems –Need to make a series of choices –Each choice is made to maximize current.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
Divide and Conquer. Problem Solution 4 Example.
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
CSC317 Greedy algorithms; Two main properties:
CSCE 411 Design and Analysis of Algorithms
Lecture on Design and Analysis of Computer Algorithm
Algorithm Design Methods
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Greedy Algorithms (Chap. 16)
Design & Analysis of Algorithm Greedy Algorithm
Greedy Algorithm.
Presented by Po-Chuan & Chen-Chen 2016/03/08
Algorithm Design Methods
Greedy Method     Greedy Matching     Coin Changing     Minimum Spanning Tree     Fractional Knapsack     Dijkstra's Single-Source Shortest-Path.
CS 3343: Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
The Greedy Method Spring 2007 The Greedy Method Merge Sort
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
CS6045: Advanced Algorithms
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Greedy Algorithm Enyue (Annie) Lu.
Exam 2 LZW not on syllabus. 73% / 75%.
Greedy Algorithms Many optimization problems can be solved more quickly using a greedy approach The basic principle is that local optimal decisions may.
Advanced Algorithms Analysis and Design
Greedy Algorithms.
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
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Richard Anderson Autumn 2016 Lecture 7
Richard Anderson Lecture 7 Greedy Algorithms
Algorithm Design Methods
Lecture 6 Greedy Algorithms
Algorithm Design Methods
The results for Challenging Problem 1.
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.
Lecture 2: Greedy Algorithms
Richard Anderson Autumn 2015 Lecture 7
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Advance Algorithm Dynamic Programming
Algorithm Design Methods
Richard Anderson Autumn 2019 Lecture 7
Presentation transcript:

CS4335 Design and Analysis of Algorithms/WANG Lusheng Greedy Algorithms: A greedy algorithm always makes the choice that looks best at the moment. It makes a local optimal choice in the hope that this choice will lead to a globally optimal solution. Greedy algorithms yield optimal solutions for many (but not all) problems. 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

The 0-1 Knapsack problem: N items, where the i-th item is worth vi dollars and weight wi pounds. 11 p 3 p 4p 58 p 8p 88p vi and wi are integers. 3$ 6 $ 35$ 8$ 28$ 66$ We can carry at most W (integer) pounds. How to take as valuable a load as possible. An item cannot be divided into pieces. The fractional knapsack problem: The same setting, but the thief can take fractions of items. W may not be integer. W 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

Solve the fractional Knapsack problem: Greedy on the value per pound vi/wi. Each time, take the item with maximum vi/wi . If exceeds W, take fractions of the item. Example: (1, 5$), (2, 9$), (3, 12$), (3, 11$) and w=4. vi/wi : 5 4.5 4.0 3.667 First: (1, 5$), Second: (2, 9$), Third: 1/3 (3, 12$) Total W: 1, 3, 4. Can only take part of item 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

Proof of correctness: (The hard part) X i1 w1 i2 w2 wj . ip wp ikwk Let X = i1, i2, …ik be the optimal items taken. Consider the item j : (vj, wj) with the highest v /w. if j is not used in X (the optimal solution), get rid of some items with total weight wj (possibly fractional items) and add item j. (since fractional items are allowed, we can do it.) Total value is increased. Why? One more item selected by greedy is added to X Repeat the process, X is changed to contain all items selected by greedy WITHOUT decreasing the total value taken by the thief. 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

The 0-1 knapsack problem cannot be solved optimally by greedy Counter example: (moderate part) W=10 2 1.8 Items found (6pounds, 12dollars), (5pounds, 9 dollar), 1.8 1. 1 (5pounds, 9 dollars), (3pounds, 3 dollars), (3 pounds, 3 dollars) If we first take (6, 12) according to greedy algorithm, then solution is (6, 12), (3, 3) (total value is 12+3=15). However, a better solution is (5, 9), (5, 9) with total value 18. To show that a statement does not hold, we only have to give an example. 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

A subset of mutually compatibles jobs: {c, f} 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

Sorting the n jobs based on fi needs O(nlog n) time 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Example: Jobs (s, f): (0, 10), (3, 4), (2, 8), (1, 5), (4, 5), (4, 8), (5, 6) (7,9). Sorting based on fi: (3, 4) (1, 5), (4, 5) (5, 6) (4,8) (2,8) (7, 9)(0,10). Selecting jobs: (3,4) (4, 5) (5,6) (7, 9) 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Sort ob finish time: b, c, a, e, d, f, g, h. Greedy algorithm Selects: b, e, h. 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Depth: The maximum No. of jobs required at any time. Depth:3 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Depth: The maximum No. of jobs required at any time. 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Greedy on start time 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Greedy Algorithm: c d g j b f i Depth: The maximum No. of jobs required at any time. a e h Depth:3 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng ddepth 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng l1=0, l2=1 l2=0, l1=0 11 10 l1=9, l2=0 l1=0, l2=1 1 11 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng di<dj We check every pair of consecutive numbers, if there is not inversion, then the whole sequenc has no inversion. n1n2 … nk Example: 1, 2, 3, 4, 5, 6, 7, 8, 9 1, 2, 6, 7, 3, 4, 5, 8, 9 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng di<dj 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng Example: Job ti di 2 2 3 4 4 6 4 8 6 10 j1 j2 5 9 13 j5 19 2 j3 j4 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng

CS4335 Design and Analysis of Algorithms/WANG Lusheng 2018/11/28 CS4335 Design and Analysis of Algorithms/WANG Lusheng