Algoritmi e strutture di dati 2



Documenti analoghi
Programmazione dinamica: Selezione di intervalli pesati. 12 ottobre 2015

Programmazione dinamica: Selezione di intervalli pesati. 4 novembre 2014

Algoritmi Priority-Driven RT. Corso di Sistemi RT Prof. Davide Brugali Università degli Studi di Bergamo

Graphs: Cycles. Tecniche di Programmazione A.A. 2012/2013

Finite Model Theory / Descriptive Complexity: bin

College Algebra. Logarithms: Denitions and Domains. Dr. Nguyen November 9, Department of Mathematics UK

U Corso di italiano, Lezione Quindici

Algoritmi greedy. Progettazione di Algoritmi a.a Matricole congrue a 1 Docente: Annalisa De Bonis

REGISTRATION GUIDE TO RESHELL SOFTWARE

Il Futuro. The Future Tense

User Guide Guglielmo SmartClient


Single-rate three-color marker (srtcm)

U Corso di italiano, Lezione Dieci

Sponsorship opportunities

AIM OF THE LESSON: for the students to familiarise themselves with the language of cooking

Compatibilità del Portale Piaggio con Internet Explorer 10 e 11. Internet Explorer 10

Esercizi Programming Contest

U Corso di italiano, Lezione Diciassette

Estendere Lean e Operational Excellence a tutta la Supply Chain

Scritto da DEApress Lunedì 14 Aprile :03 - Ultimo aggiornamento Martedì 26 Maggio :34

Stringhe. Prof. Lorenzo Porcelli

UNIVERSITÀ DEGLI STUDI DI TORINO

Schedulazione di attività in presenza di attività interrompibili

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

A.A. 2006/2007 Laurea di Ingegneria Informatica. Fondamenti di C++ Horstmann Capitolo 3: Oggetti Revisione Prof. M. Angelaccio

Novità versione 10 News release 10

Data Alignment and (Geo)Referencing (sometimes Registration process)

I CAMBIAMENTI PROTOTESTO-METATESTO, UN MODELLO CON ESEMPI BASATI SULLA TRADUZIONE DELLA BIBBIA (ITALIAN EDITION) BY BRUNO OSIMO

-Fig.1-

Copyright 2012 Binary System srl Piacenza ITALIA Via Coppalati, 6 P.IVA info@binarysystem.eu

THIS DOCUMENT WILL GUIDE YOU STEP BY STEP THROUGH THE DONATION PROCESS RELATED TO THE CROWDFUNDING CAMPAIGN MADE BY STANZE AL GENIO S HOUSE MUSEUM.

Sponsorship opportunities

Scuola Sec. Secondo Grado FINALE IND. - 14/15 ESERCIZIO 1

ESISTENZA DI INFINITI NUMERI PRIMI REGOLARI. Francesco Di Noto, Michele Nardelli. In this paper we describe about the regular prime

Le cellule staminali dell embrione: cosa possono fare Embryonic stem cells are exciting because they can make all the different types of cell in the

Sommario. Esempio di Modellazione mediante DASM: Grid OGSA. Grid secondo OGSA. Definizione Grid per OGSA. Stati di un Job e Requisiti DASM

Mod. EASYCUP EASYCUP WITH LED PANEL: MINIMUM THICK!!!

U Corso di italiano, Lezione Sedici

Mark Scheme (Results) Summer 2007

Pezzi da ritagliare, modellare e incollare nell ordine numerico indicato.

Calcolo efficienza energetica secondo Regolamento UE n. 327/2011 Energy efficiency calculation according to EU Regulation no.

Sistemi Operativi II Corso di Laurea in Ingegneria Informatica

Risultati del Questionario sulla soddisfazione degli utenti di Technology Innovation

Quando mi collego ad alcuni servizi hosting ricevo un messaggio relativo al certificato di protezione del sito SSL, come mai?

CONFIGURATION MANUAL

Prova finale di Ingegneria del software

Downloading and Installing Software Socio TIS

EVENTI (PRIVATE DINNER) F A B R I Z I O

You can visualize the free space percentage in Compact Flash memory from the MENU/INFO C.F. UTILITY-FREE SPACE page.

Scheda Allarmi Alarm Board MiniHi

100 mm - 107,5 mm PCB Width: in in (100 mm mm)

INFORMAZIONE AGLI UTENTI DI APPARECCHIATURE DOMESTICHE O PROFESSIONALI

1. Classificazione delle risorse

PREMESSA (diapositive 1, 2, 3) PER UNA DISTRIBUZIONE SFERICA DI MASSA contenuta all interno della superficie S:

EN IT. Computer Manual. Manuale computer. Console

UNIVERSITÀ DEGLI STUDI DI TORINO. Instructions to apply for exams ONLINE Version 01 updated on 17/11/2014

True CMS USER MANUAL

Introduzione Kerberos. Orazio Battaglia

Sezione 1 / Section 1. Elementi d identità: il marchio Elements of identity: the logo

Come noterete più sotto, avendone avuta richiesta esplicita, da oggi unisco alla versione italiana anche una inglese del post. Passiamo all'argomento.

ISAC. Company Profile

Portale Materiali Grafiche Tamburini. Grafiche Tamburini Materials Portal

Babaoglu 2006 Sicurezza 2

rasomuro 41_ muratura-wall istruzioni di montaggio

How to use the WPA2 encrypted connection

Transcript:

Algoritmi e strutture di dati 2 Paola Vocca Lezione 2: Tecniche golose (greedy) Lezione1- Divide et impera 1 Progettazione di algoritmi greedy Tecniche di dimostrazione (progettazione) o Greedy algorithms stays ahead: Ad ogni passo la scelta effettuata dall algoritmo risulta migliore rispetto alla soluzione ottima o Exachage algorithm: trasformazione di una qualsiasi soluzione ottima nella soluzione trovata dall algoritmo senza alterare la misura della soluzione Algoritmi e strutture di dati 2 Lezione1- Divide et impera 2 1

Algoritmi golosi Un algoritmo goloso basa le sue scelte sulla configurazione attuale senza valutare le conseguenze sulle configurazioni successive Il paradigma dell algoritmo goloso non è facilmente formalizzabile Il successo di tale tecnica dipende da proprietà strutturali del problema o Problemi già affrontati o Cammino minimo o Minimum spannning tree Algoritmi e strutture di dati 2 Lezione1- Divide et impera 3 Interval scheduling Job j starts at and finishes at. Two jobs compatible if they don't overlap. Goal: find maximum subset of mutually compatible jobs. a b c d e f g h Algoritmi e strutture di dati 2 Lezione1- Divide et impera 4 2

Interval Scheduling: Greedy Algorithms Greedy template. Consider jobs in some natural order. Take each job provided it's compatible with the ones already taken. [Earliest start time] Consider jobs in ascending order of. [Earliest finish time] Consider jobs in ascending order of. [Shortest interval] Consider jobs in ascending order of. [Fewest conflicts] For each job, count the number of conflicting jobs. Schedule in ascending order of. Algoritmi e strutture di dati 2 Lezione1- Divide et impera 5 Interval Scheduling: Greedy Algorithms Greedy template. Consider jobs in some natural order. Take each job provided it's compatible with the ones already taken. [Earliest start time] Consider jobs in ascending order of. o Does it work? o 1st Step of Problem Solvers: Find bad situations for the Algorithm. counterexample for earliest start time Algoritmi e strutture di dati 2 Lezione1- Divide et impera 6 3

Interval Scheduling: Greedy Algorithms Greedy template. Consider jobs in some natural order. Take each job provided it's compatible with the ones already taken. [Shortest interval] Consider jobs in ascending order of. Bad Situations??? counterexample shortest interval Algoritmi e strutture di dati 2 Lezione1- Divide et impera 7 Interval Scheduling: Greedy Algorithms Greedy template. Consider jobs in some natural order. Take each job provided it's compatible with the ones already taken. [Fewest conflicts] For each job, count the number of conflicting jobs. Schedule in ascending order of. o IDEA: Use GRAPH MODELLING; o Which is the problem in terms of GRAPHS? counterexample shortest interval Algoritmi e strutture di dati 2 Lezione1- Divide et impera 8 4

Interval Scheduling: Greedy Algorithms Greedy template Consider jobs in increasing order of finish time. Take each job provided it's compatible with the ones already taken Implementation.. o Remember job that was added last to. o Job is compatible with if A is a compatible set of request Algoritmi e strutture di dati 2 Lezione1- Divide et impera 9 Example Algoritmi e strutture di dati 2 Lezione1- Divide et impera 10 5

Interval Scheduling: Analysis (2) Theorem. Greedy algorithm is optimal. Proof o o o o o Sia l insieme ottimo degli intervalli e l insieme riportato dall algoritmo Dimostriamo = (non possiamo dimostrare che = perché potrebbero esserci più soluzioni ottime) Let,, denote set of jobs selected by greedy. (ordine in cui vengono selezionate) Let,, denote set of jobs in the optimal solution (ordinate per inzio crescente stesso ordine della fine poichè gli intervalli sono compatibili). La dimostrazione procede in due passi 1. For all indices we have (per induzione) 2. The greedy algorithm returns an optimal set A. (by contradiction) Algoritmi e strutture di dati 2 Lezione1- Divide et impera 11 Interval Scheduling: Analysis Theorem. For all indices we have Proof (by induction) 1. Caso base: vero per costruzione 2. Passo r-th: Per induzione 1 (l algoritmo greedy sceglie sempre l intervallo che termina prima. The greedy algorithm stays ahead! "#! "? Can the greedy algorithm s r th interval really finish later? "# " Algoritmi e strutture di dati 2 Lezione1- Divide et impera 12 6

Interval Scheduling: Analysis (2) Theorem. The greedy algorithm returns an optimal set A. Proof (by contradiction) o Supponiamo che > % >& o esiste ' in compatibile con le richieste precedenti. o Assurdo altrimenti sarebbe stato scelto dall algoritmo greedy. Algoritmi e strutture di dati 2 Lezione1- Divide et impera 13 Interval Partitioning Interval partitioning. Many identical resources Many requests Goal: find minimum number of resources to schedule all requests without ovelapping Algoritmi e strutture di dati 2 Lezione1- Divide et impera 14 7

Interval Partioning Example Example o Lecture starts at and finishes at. o Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room. o This schedule uses 4 classrooms to schedule 10 lectures. c d g b a f e h j i This schedule uses only 3 classrooms c d f j b g i a e h Algoritmi e strutture di dati 2 Lezione1- Divide et impera 15 Interval Partitioning: Lower Bound on Optimal Solution Def.: The depth of a set intervals to be the maximum number that pass over any single point on the time-line. Claim: In any instance of the Interval Partitioning, the number of resources needed depth. c d f j b g i a e h Algoritmi e strutture di dati 2 Lezione1- Divide et impera 16 8

Strategia E possibile determinare un algoritmo che utilizzi sempre il minimo numero di risorse? Esiste sempre uno scheduling che utilizza un numero di risorse pari alla profondità? Greedy algorithm. Consider intervals in increasing order of start time: assign an interval to any compatible resource Sort the intervals by their start times, breaking ties arbitrarily Let ( #,( ),.,( denote the intervals in this order For = #,),*.., For each interval (! that precedes ( in sorted order and overlaps it Exclude the label of Endfor If there is any label from {#,),..,,} that has not been excluded then Assign a nonexcluded label to ( Else Leave ( unlabeled Endif Endfor Algoritmi e strutture di dati 2 Lezione1- Divide et impera 17 Interval Partitioning: Greedy Algorithm Implementation. log. o For each resource, maintain the finish time of the last job added. o Keep the resource in a priority queue. Algoritmi e strutture di dati 2 Lezione1- Divide et impera 18 9

Interval Partitioning: Greedy Analysis Theorem. Greedy algorithm is optimal. Pf(Idea). 1. Every interval will be assigned a label; 2. No two incompatible intervals receive the same label Let ( and suppose there are 1 intervals overlapping There are 2+1 4 overlapping intervals 2< 4. No two incompatible intervals receive the same label: Since we sorted by start time, all these incompatibilities are caused by jobs that start no later than. all labels have been excluded, is a lower bound the algorithm is optimal. Algoritmi e strutture di dati 2 Lezione1- Divide et impera 19 Scheduling to Minimizing Lateness Algoritmi e strutture di dati 2 Lezione1- Divide et impera 20 10

Minimizing Lateness: Greedy Algorithms Algoritmi e strutture di dati 2 Lezione1- Divide et impera 21 Minimizing Lateness: Greedy Algorithms Algoritmi e strutture di dati 2 Lezione1- Divide et impera 22 11

Minimizing Lateness: Greedy Algorithms Algoritmi e strutture di dati 2 Lezione1- Divide et impera 23 Minimizing Lateness: Greedy Algorithm Algoritmi e strutture di dati 2 Lezione1- Divide et impera 24 12

Minimizing Lateness: No Idle Time Algoritmi e strutture di dati 2 Lezione1- Divide et impera 25 Minimizing Lateness: Inversions By construction Algoritmi e strutture di dati 2 Lezione1- Divide et impera 26 13

Minimizing Lateness: Inversions Algoritmi e strutture di dati 2 Lezione1- Divide et impera 27 Minimizing Lateness: Analysis of Greedy Algorithm Algoritmi e strutture di dati 2 Lezione1- Divide et impera 28 14

Greedy Analysis Strategies Algoritmi e strutture di dati 2 Lezione1- Divide et impera 29 Optimal Offline Caching Algoritmi e strutture di dati 2 Lezione1- Divide et impera 30 15

Optimal Offline Caching: Farthest-In- Future Algoritmi e strutture di dati 2 Lezione1- Divide et impera 31 Reduced Eviction Schedules In a reduced schedule the number of insertions is equal to the number of misses Algoritmi e strutture di dati 2 Lezione1- Divide et impera 32 16

Reduced Eviction Schedules Algoritmi e strutture di dati 2 Lezione1- Divide et impera 33 Farthest-In-Future: Analysis Algoritmi e strutture di dati 2 Lezione1- Divide et impera 34 17

Farthest-In-Future: Analysis same e f same e f same e d same d f Algoritmi e strutture di dati 2 Lezione1- Divide et impera 35 Farthest-In-Future: Analysis same e same f Algoritmi e strutture di dati 2 Lezione1- Divide et impera 36 18

Farthest-In-Future: Analysis same e same f same g same g Algoritmi e strutture di dati 2 Lezione1- Divide et impera 37 Caching Perspective Algoritmi e strutture di dati 2 Lezione1- Divide et impera 38 19