CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Greedy Algorithms.
1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
Greedy Algorithms Greed is good. (Some of the time)
Analysis of Algorithms
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Dynamic Programming.
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 1 (Part 3) Tuesday, 9/4/01 Greedy Algorithms.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Chapter 9 Greedy Technique Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
CSE 780 Algorithms Advanced Algorithms Greedy algorithm Job-select problem Greedy vs DP.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Lecture 1 (Part 3) Tuesday, 1/29/02 Design Patterns for Optimization.
Greedy Algorithms CSE 331 Section 2 James Daly. Reminders Exam 2 next week Thursday, April 9th Covers heaps to spanning trees Greedy algorithms (today)
Lecture 10 Matroid. Independent System Consider a finite set S and a collection C of subsets of S. (S,C) is called an independent system if i.e., it is.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
16.Greedy algorithms Hsu, Lih-Hsing. Computer Theory Lab. Chapter 16P An activity-selection problem Suppose we have a set S = {a 1, a 2,..., a.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
 Greedy Algorithms. Greedy Algorithm  Greedy Algorithm - Makes locally optimal choice at each stage. - For optimization problems.  If the local optimum.
Data Structures and Algorithms A. G. Malamos
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Greedy Algorithms Input: Output: Objective: - make decisions “greedily”, previous decisions are never reconsidered Optimization problems.
Greedy Algorithms Jeff Chastine. Greedy Algorithms Compared to Dynamic Programming – Both used in optimization problems – More efficient – Not always.
Dynamic programming vs Greedy algo – con’t Input: Output: Objective: a number W and a set of n items, the i-th item has a weight w i and a cost c i a subset.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Bahareh Sarrafzadeh 6111 Fall 2009
1 Algorithms CSCI 235, Fall 2015 Lecture 30 More Greedy Algorithms.
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
Greedy Algorithms Chapter 16 Highlights
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 2 Tuesday, 2/2/10 Design Patterns for Optimization.
1 Chapter 16: Greedy Algorithm. 2 About this lecture Introduce Greedy Algorithm Look at some problems solvable by Greedy Algorithm.
Greedy Algorithms Analysis of Algorithms.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Greedy Algorithms. p2. Activity-selection problem: Problem : Want to schedule as many compatible activities as possible., n activities. Activity i, start.
CS6045: Advanced Algorithms Greedy Algorithms. Main Concept –Divide the problem into multiple steps (sub-problems) –For each step take the best choice.
Greedy Algorithms General principle of greedy algorithm
HUFFMAN CODES.
Greedy Algorithms Alexandra Stefan.
CSC317 Greedy algorithms; Two main properties:
Greedy Technique.
Greedy Method 6/22/2018 6:57 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
The Greedy Method and Text Compression
Greedy Algorithms (Chap. 16)
The Greedy Method and Text Compression
Introduction to Algorithms`
Greedy Algorithm.
Chapter 16: Greedy Algorithms
Lecture 9 Greedy Strategy
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
CS6045: Advanced Algorithms
Greedy Algorithms Many optimization problems can be solved more quickly using a greedy approach The basic principle is that local optimal decisions may.
Chapter 16: Greedy algorithms Ming-Te Chi
Greedy Algorithms.
Lecture 6 Topics Greedy Algorithm
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Data Structure and Algorithms
Greedy Algorithms Alexandra Stefan.
Chapter 16: Greedy algorithms Ming-Te Chi
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Podcast Ch23d Title: Huffman Compression
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Huffman Coding Greedy Algorithm
Algorithms CSCI 235, Spring 2019 Lecture 31 Huffman Codes
Analysis of Algorithms CS 477/677
Presentation transcript:

CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)

Greedy Algorithm (Chapter 16) For many optimization problem, a dynamic problem is just overkill; when? If we can make the optimal choice before finding optimal values of the sub- problems. – We just make the choice that looks best at the moment; that justify the name, “greedy” For many problems, greedy solution does not yield optimal solution, for many it does – Activity-Selection problem (greedy works) – Minimum Spanning Tree (greedy works) – Vertex Cover (greedy does not work) In a dynamic programming solution, we solve the sub-problem first and then use that to find optimal choices for solving larger problems – What if that optimal choice can be achieved without knowing the optimal value of the sub- problems – In other words, the choice that you make greedily is the same as the optimal choice

Activity-Selection problem I S(i) F(i) {2, 4, 9, 11} can be one answer

One Solution approach using DP

A better DP Solution (we have shown it’s weighted version in earlier class)

Solution Using Greedy approach

How do we know whether it works

Elements of greedy strategy Two important criteria need to be satisfied – Greedy choice property (locally optimal choice will ultimately provide a global optimal solution) – Optimal sub-structure property Greedy algorithm design steps – Cast the optimization problem as one in which we can make a choice using a greedy criteria and are left with one sub-problem to solve – Prove that there is always an optimal solution to the original problem that makes the greedy choice (greedy choice is safe)

Greedy vs Dynamic Dynamic – Optimal Substructure property – Smaller sub-problems need to be solved first, as their optimal value affects the choice we make when we solve the larger problems – Sub-problems are overlapping, so memoization is important Greedy – Optimal substructure property – Smaller sub-problem don’t need to be solved first, as greedy choice let us solve the problem top-down – After greedy choice, only one sub-problem exist, so sub- problems are not overlapping

Huffman Codes Huffman codes are used to compress data by encoding each character to a binary string – The compression is non-lossy. Such codes are prefix-free code (also known as prefix codes), i.e., no codeword is a prefix of some other codeword. – Prefix codes are optimal (no proof) – No delimiter is required between two codewords in the compressed file The idea of compression is to use variable-length codes instead of fixed length code – The most frequent character should have the shortest-length code, and the rarest character should have the longest-length code – Huffman proposed a greedy algorithm that find coding that is optimal among all prefix-free codes. – Optimality is defined over the expected length of each codeword

Example 30,000 bit for a 10,000 character file) 22,400 bit for a 10,000 character file)

Constructing Huffman code

Pseudo-code

Example

Correctness Proof

Correctness Proof (cont.)

Knapsack problem

Matroids and Greedy Methods

Example: Graphical Metroid

Matroid (cont.)

Greedy algorithm on weighted matroid

Scheduling unit-time tasks with penalty

Canonical Scheduling

Lemma 16.12

Lemma (cont.)

Task with Deadlines shows Matroid property

Greedy Algorithm for Unit-length task with penalty