CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 9: Greedy

Similar documents
Route optimization using Hungarian method combined with Dijkstra's in home health care services

Real-Time Systems Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Lecture 3: Nondeterministic Computation

1) What is the standard divisor? A) 30.1 B) 903 C) 6.38 D) 6.88 E) 16.74

Algorithms, Lecture 3 on NP : Nondeterministic Polynomial Time

Chapter 12. Synchronous Circuits. Contents

Unit 2: Graphing Part 5: Standard Form

Part I: Graph Coloring

Heuristic Search & Local Search

Previous Lecture Sequential Circuits. Slide Summary of contents covered in this lecture. (Refer Slide Time: 01:55)

Modelling a master detail scheduler for the laboratory

Peak Dynamic Power Estimation of FPGA-mapped Digital Designs

Mathematics, Proofs and Computation

CPSC 121: Models of Computation. Module 1: Propositional Logic

Problem 1 - Protoss. bul. Alexander Malinov 33., Sofia, 1729, Bulgaria academy.telerik.com

CSC 373: Algorithm Design and Analysis Lecture 17

Permutations of the Octagon: An Aesthetic-Mathematical Dialectic

Lesson 25: Solving Problems in Two Ways Rates and Algebra

Broadcast Networks with Arbitrary Channel Bit Rates

6.S084 Tutorial Problems L05 Sequential Circuits

Melodic Pattern Segmentation of Polyphonic Music as a Set Partitioning Problem

Corinne: I m thinking of a number between 220 and 20. What s my number? Benjamin: Is it 25?

Department of Electrical and Computer Engineering University of Wisconsin Madison. Fall Final Examination CLOSED BOOK

Using Scan Side Channel to Detect IP Theft

Cryptanalysis of LILI-128

B291B. MATHEMATICS B (MEI) Paper 1 Section B (Foundation Tier) GENERAL CERTIFICATE OF SECONDARY EDUCATION. Friday 9 January 2009 Morning

Combinational vs Sequential

CS 2104 Intro Problem Solving in Computer Science Test 1 READ THIS NOW!

MULTI-CYCLE AT SPEED TEST. A Thesis MALLIKA SHREE POKHAREL

AutoChorale An Automatic Music Generator. Jack Mi, Zhengtao Jin

Double Patterning OPC and Design for 22nm to 16nm Device Nodes

Achieving Faster Time to Tapeout with In-Design, Signoff-Quality Metal Fill

VLSI System Testing. BIST Motivation

Preliminaries. for the Benelux Algorithm Programming Contest. Problems

Bite Size Brownies. Designed by: Jonathan Thompson George Mason University, COMPLETE Math

Optimization of Multi-Channel BCH Error Decoding for Common Cases. Russell Dill Master's Thesis Defense April 20, 2015

m RSC Chromatographie Integration Methods Second Edition CHROMATOGRAPHY MONOGRAPHS Norman Dyson Dyson Instruments Ltd., UK

Final Exam CPSC/ECEN 680 May 2, Name: UIN:

140 IEEE TRANSACTIONS ON VERY LARGE SCALE INTEGRATION (VLSI) SYSTEMS, VOL. 12, NO. 2, FEBRUARY 2004

Yale University Department of Computer Science

A combination of approaches to solve Task How Many Ratings? of the KDD CUP 2007

Topic 10. Multi-pitch Analysis

Math Final Exam Practice Test December 2, 2013

Atlas Drop In Decoder

Multiple Strategies to Analyze Monty Hall Problem. 4 Approaches to the Monty Hall Problem

CPM Schedule Summarizing Function of the Beeline Diagramming Method

EEC 116 Fall 2011 Lab #5: Pipelined 32b Adder

Linköping University Post Print. Quasi-Static Voltage Scaling for Energy Minimization with Time Constraints

Daily Team Planner (DTP)

PCIe: EYE DIAGRAM ANALYSIS IN HYPERLYNX

Processing the Output of TOSOM

PHI 3240: Philosophy of Art

Processes for the Intersection

OPERATIONS SEQUENCING IN A CABLE ASSEMBLY SHOP

Scheduler Activity Instructions

CPS311 Lecture: Sequential Circuits

Sudoku Music: Systems and Readymades

PROF. TAJANA SIMUNIC ROSING. Midterm. Problem Max. Points Points Total 150 INSTRUCTIONS:

Low-Floor Decoders for LDPC Codes

Analysis of Caprice No. 42. Throughout George Rochberg s Caprice No. 42, I hear a kind of palindrome and inverse

A Framework for Segmentation of Interview Videos

MidiFind: Fast and Effec/ve Similarity Searching in Large MIDI Databases

Combinational Logic Design

THE MAJORITY of the time spent by automatic test

CS8803: Advanced Digital Design for Embedded Hardware

VISUAL CONTENT BASED SEGMENTATION OF TALK & GAME SHOWS. O. Javed, S. Khan, Z. Rasheed, M.Shah. {ojaved, khan, zrasheed,

Implementing a Rudimentary Oscilloscope

Algorithmic Music Composition

Proofs That Are Not Valid. Identify errors in proofs. Area = 65. Area = 64. Since I used the same tiles: 64 = 65

G.709 FEC testing Guaranteeing correct FEC behavior

LAB 1: Plotting a GM Plateau and Introduction to Statistical Distribution. A. Plotting a GM Plateau. This lab will have two sections, A and B.

Lossless Compression Algorithms for Direct- Write Lithography Systems

What is Statistics? 13.1 What is Statistics? Statistics

Phrasal Verbs to Use at Work

Cambridge International Examinations Cambridge International General Certificate of Secondary Education

Music Source Separation

General Certificate of Education Advanced Subsidiary Examination June Problem Solving, Programming, Data Representation and Practical Exercise

Random Access Scan. Veeraraghavan Ramamurthy Dept. of Electrical and Computer Engineering Auburn University, Auburn, AL

Performance evaluation of I 3 S on whale shark data

VISSIM TUTORIALS This document includes tutorials that provide help in using VISSIM to accomplish the six tasks listed in the table below.

Precision testing methods of Event Timer A032-ET

Analysis of MPEG-2 Video Streams

Bach in a Box - Real-Time Harmony

Facedown Low-Inductance Solder Pad and Via Schemes Revision 0 - Aug 8, Low ESL / 7343 Package

Slide Set 9. for ENCM 501 in Winter Steve Norman, PhD, PEng

Post-Routing Layer Assignment for Double Patterning

ECE 4220 Real Time Embedded Systems Final Project Spectrum Analyzer

Calculated Percentage = Number of color specific M&M s x 100% Total Number of M&M s (from the same row)

DUE to the popularity of portable electronic products,

(Refer Slide Time: 1:45)

Advanced Data Structures and Algorithms

Building a Better Bach with Markov Chains

Jazz Melody Generation and Recognition

Power Reduction Approach by using Multi-Bit Flip-Flops

Music Segmentation Using Markov Chain Methods

Digital Video Recorder From Waitsfield Cable

GRAPH-BASED RHYTHM INTERPRETATION

Adaptive decoding of convolutional codes

Laboratory Assignment 3. Digital Music Synthesis: Beethoven s Fifth Symphony Using MATLAB

AskDrCallahan Calculus 1 Teacher s Guide

Transcription:

CSE 101 Algorithm Design and Analysis Miles Jones mej016@eng.ucsd.edu Office 4208 CSE Building Lecture 9: Greedy

GENERAL PROBLEM SOLVING In general, when you try to solve a problem, you are trying to find a solution from among a large space of possibilities. You usually do this by making a series of decisions and continuing based on what the new state of the problem has become.

GENERAL PROBLEM SOLVING In general, when you try to solve a problem, you are trying to find a solution from among a large space of possibilities. You usually do this by making a series of decisions and continuing based on what the new state of the problem has become. If you have no information about which choice is best, you may have to use exhaustive enumeration or Brute Force to try out all possibilities and find the optimal one. This might take a long time to do. What are some other ideas in general?

THE GREEDY METHOD In some cases (not all!!!!!), there is sufficient structure that allows you to reach the correct solution by just picking the straightforward best decision at each stage. This is called the Greedy Method.

THE GREEDY METHOD In some cases (not all!!!!!), there is sufficient structure that allows you to reach the correct solution by just picking the straightforward best decision at each stage. This is called the Greedy Method. It doesn t always work. Just as in life, acting in one s immediate best interest is not always the best longer-term strategy.

COOKIES Suppose you are the cookie monster and you have a 6x6 sheet of freshly baked cookies in front of you. The cookies are all chocolate chip cookies but they may have different sizes If you are only allowed to take six cookies. Devise an algorithm to do this.

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 1. What is an algorithm you could use to select the best option? (The best option means that the sum of all the cookie s sizes is the highest possible.)

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 1. What is an algorithm you could use to select the best option? (The best option means that the sum of all the cookie s sizes is the highest possible.) 99+97+94+92+88+85=555

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 2. What is an algorithm you could use to select the best option if you can only select one cookie from each row? 78 81 79 71 85 62 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 2. What is an algorithm you could use to select the best option if you can only select one cookie from each row? 76+80+99+68+85+73=481 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 50 67 73 57 70 46

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 99+81+74+60+50+40=404

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 99+81+74+60+50+40=404 99+81+72+69+47+46=414

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 99+81+74+60+50+40=404 99+81+72+69+47+46=414 92+78+75+73+72+68=458!!!!!!!!

COOKIES 56 76 69 60 75 51 61 77 74 72 80 58 82 97 94 88 99 92 47 68 59 52 65 40 78 81 79 71 85 62 50 67 73 57 70 46 3. What is an algorithm you could use to select the best option if you can t select 2 cookies from the same row or column? 99+81+74+60+50+40=404 99+81+72+69+47+46=414 92+78+75+73+72+68=458!!!!!!!!

THE GREEDY METHOD As you have seen, the Greedy Method does not always work. Because of this, in order to use the Greedy Method, we must prove the correctness of the algorithm. Or else, we must present a counterexample to show that a particular greedy method will not work.

THE GREEDY METHOD (WARNING!!) As you have seen, the Greedy Method does not always work. Because of this, in order to use the Greedy Method, we must prove the correctness of the algorithm. Furthermore, for a single problem, there may be more than one potential greedy strategy i.e. more than one way to choose the best possible choice at each step. The problem may be solved in one way but not the other.

GREEDY DIJKSTRA S We have already seen a greedy algorithm. Instance: a graph with positive edge weights and a vertex s Solution form: dist(v) is the length of a path from s to v Constraints: No constraints that are not obvious Objective: dist(v) is set to the minimum distance from s to v

GREEDY DIJKSTRA S What is the greedy property? Pick the next vertex u such that the distance from s to u is smallest (and u has not been picked yet.)

EVENT SCHEDULING Suppose you are running a conference and you have a collection of events (or talks) that each have a start time and an end time. Oh no!!! You only have one conference room!!!! Your goal is to schedule the most events possible that day such that no two events overlap.

EVENT SCHEDULING Your goal is to schedule the most events possible that day such that no two events overlap. Brute Force: Say that T is the set of events and T =n. Let s check all possibilities. How would we do that?

EVENT SCHEDULING Your goal is to schedule the most events possible that day such that no two events overlap. Brute Force: Say that T is the set of events and T =n. Let s check all possibilities. How would we do that? Go through all subsets of T. Check if it is a valid schedule, i.e., no conflicts, and count the number of events. Take the maximum out of all valid schedules. (How many subsets of T are there?)

EVENT SCHEDULING 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

EVENT SCHEDULING Your goal is to schedule the most events possible that day such that no two events overlap. Exponential is too slow. Let s try some greedy strategies:

EVENT SCHEDULING Your goal is to schedule the most events possible that day such that no two events overlap. Exponential is too slow. Let s try some greedy strategies: Shortest duration Earliest start time Fewest conflicts Earliest end time

SHORTEST DURATION 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

EARLIEST START TIME 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

FEWEST CONFLICTS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

COUNTEREXAMPLE FOR FEWEST CONFLICTS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

EARLIEST FINISH TIME 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

EVENT SCHEDULING Your goal is to schedule the most events possible that day such that no two events overlap. Exponential is too slow. Let s try some greedy strategies: Shortest duration Earliest start time Fewest conflicts Earliest end time (We can t find a counterexample!!) Let s try to prove it works!!!!!

EVENT SCHEDULING 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

MODIFY-THE-SOLUTION There are a few proof techniques to prove greedy strategies work. We will use modify-the-solution to prove the correctness of this greedy strategy. General structure of modify-the-solution: 1. Let d be a decision point, and let g be the greedy choice at d. 2. Let S be a solution achieved by not choosing g. 3. Show how to transform S into some solution S that chooses g, and that is at least as good as S Conclude (by induction) that any S with a series of non-greedy decisions at d 1,, d n can be transformed into an equal-or-better greedy solution, and that therefore the greedy algorithm is optimal.