SlideShare a Scribd company logo
EFFICIENZA
&
CORRETTEZZA
di un algoritmo
Perché efficienza e correttezza sono così
importanti?
Vediamo un esempio 
Abbiamo visto come le soluzioni ad un problema
siano molteplici, una volta trovate queste
soluzioni dobbiamo però sceglierne una.
• Quale scegliere?
• Come scegliamo la migliore?
Confrontiamo due soluzioni
Ricerca sequenziale Ricerca binaria
Come misuriamo?
Caso MIGLIORE Caso STANDARD Caso PEGGIORE
Ω(f(n)) Θ(g(n)) Ο(h(n))
Proviamo!
Tempod’esecuzione
Dimensione input
Insertion sort
Tempod’esecuzione
Dimensione input
Correttezza: errori celebri
Sonda spaziale USA distrutta da un trattino (1962)
La sonda automatica Mariner 1 decolla da Cape Canaveral,
ma invece di dirigersi verso Venere, subito dopo il lancio
piega a sinistra e punta verso il basso. La NASA è costretta
a farla esplodere in volo.
Il rapporto pubblicato in seguito dalla NASA ammette che
la causa dell'errore è un singolo trattino mancante da una
riga di codice.
La rete interurbana della AT&T collassa (1990)
Errori di commutazione nei computer di gestione delle
chiamate della AT&T rendono inutilizzabile per nove ore
la rete interurbana e interstatale statunitense della società.
La causa del collasso fu poi attribuita a una singola riga
di codice errata.
I missili Patriot durante la guerra del Golfo (1991)
Durante la Guerra del Golfo, il sistema antimissile americano Patriot
intercetta numerosi missili iracheni, ma fallisce frequentemente.
Gli errori derivano da un errore nel software, che introduce uno scarto
di 0,34 secondi. Il sistema antimissile era concepito per funzionare
ininterrottamente per un massimo di 14 ore. Durante l'attacco a Dhahran,
la batteria difensiva di Patriot era rimasta in funzione per 100 ore senza
interruzioni. I militari avevano già individuato il problema, ma non
riuscirono a trasmettere la correzione in tempo utile.
Aeroporto avveniristico messo in ginocchio dallo smistamento bagagli (1995)
Il nuovissimo Denver International Airport doveva essere all'avanguardia, con il suo
complesso sistema computerizzato di smistamento. Ma dei difetti nel sistema di
smistamento finirono per tritare alcune valigie e far schiantare contro i muri i carrelli automatici.
L'aeroporto fu costretto ad aprire 16 mesi dopo la data prevista, con uno sforamento
di 3,2 miliardi di dollari rispetto ai preventivi e con un sistema di smistamento
bagagli quasi interamente manuale.
Il vettore Ariane 5 esplode al decollo, danni per 1 miliardo di euro (1996)
Il 4 giugno 1996 viene lanciato per la prima volta il vettore Ariane 5,
punta di diamante del programma spaziale europeo. Dopo 39 secondi
di volo interviene il sistema di autodistruzione, trasformando l'Ariane 5
e il suo carico pagante (quattro satelliti scientifici non assicurati) in quello
che è stato definito "il più costoso fuoco d'artificio della storia".
Il disastro avviene perché un programma del sistema di navigazione tenta
di mettere un numero a 64 bit in uno spazio a 16 bit. In pratica viene ritenuto
affidabile il software dell'Ariane 4 e quindi installato sull'Ariane 5.
Risultato: spegnimento del sistema di guida, e trasferimento del controllo
al secondo sistema di guida andato in tilt nella medesima maniera pochi
millisecondi prima. Privo di guida, il vettore si autodistrugge.
Nave da guerra USA va in crash grazie a Windows (1997)
Nel settembre del 1997, l'incrociatore lanciamissili USS Yorktown,
comandato da un avanzatissimo sistema di gestione computerizzata
basato su Windows NT, va in crisi per un buffer overflow che
costringe la nave a restare paralizzata in mare per due ore.
Il Millennium Bug (2000)
Per decenni i programmatori hanno risparmiato spazio usando
solo due cifre per rappresentare gli anni. Ma all'arrivo del 2000,
qualsiasi apparecchio che faccia calcoli sulle date rischia di
andare in crisi perché crede di essere nel 1900.
Si stima che la spesa complessiva mondiale per risolvere il
Millennium Bug ammonti a 400 miliardi di dollari.
Correttezza
La correttezza di un programma è...
NON QUELLA DI UN
ALGORITMO
Why?
Verificare un algoritmo
Grazie dell’attenzione e
Buono Studio

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Lezione "Efficienza & Correttezza"

  • 2. Perché efficienza e correttezza sono così importanti? Vediamo un esempio 
  • 3. Abbiamo visto come le soluzioni ad un problema siano molteplici, una volta trovate queste soluzioni dobbiamo però sceglierne una. • Quale scegliere? • Come scegliamo la migliore?
  • 4. Confrontiamo due soluzioni Ricerca sequenziale Ricerca binaria
  • 5. Come misuriamo? Caso MIGLIORE Caso STANDARD Caso PEGGIORE Ω(f(n)) Θ(g(n)) Ο(h(n))
  • 10. Correttezza: errori celebri Sonda spaziale USA distrutta da un trattino (1962) La sonda automatica Mariner 1 decolla da Cape Canaveral, ma invece di dirigersi verso Venere, subito dopo il lancio piega a sinistra e punta verso il basso. La NASA è costretta a farla esplodere in volo. Il rapporto pubblicato in seguito dalla NASA ammette che la causa dell'errore è un singolo trattino mancante da una riga di codice. La rete interurbana della AT&T collassa (1990) Errori di commutazione nei computer di gestione delle chiamate della AT&T rendono inutilizzabile per nove ore la rete interurbana e interstatale statunitense della società. La causa del collasso fu poi attribuita a una singola riga di codice errata. I missili Patriot durante la guerra del Golfo (1991) Durante la Guerra del Golfo, il sistema antimissile americano Patriot intercetta numerosi missili iracheni, ma fallisce frequentemente. Gli errori derivano da un errore nel software, che introduce uno scarto di 0,34 secondi. Il sistema antimissile era concepito per funzionare ininterrottamente per un massimo di 14 ore. Durante l'attacco a Dhahran, la batteria difensiva di Patriot era rimasta in funzione per 100 ore senza interruzioni. I militari avevano già individuato il problema, ma non riuscirono a trasmettere la correzione in tempo utile. Aeroporto avveniristico messo in ginocchio dallo smistamento bagagli (1995) Il nuovissimo Denver International Airport doveva essere all'avanguardia, con il suo complesso sistema computerizzato di smistamento. Ma dei difetti nel sistema di smistamento finirono per tritare alcune valigie e far schiantare contro i muri i carrelli automatici. L'aeroporto fu costretto ad aprire 16 mesi dopo la data prevista, con uno sforamento di 3,2 miliardi di dollari rispetto ai preventivi e con un sistema di smistamento bagagli quasi interamente manuale. Il vettore Ariane 5 esplode al decollo, danni per 1 miliardo di euro (1996) Il 4 giugno 1996 viene lanciato per la prima volta il vettore Ariane 5, punta di diamante del programma spaziale europeo. Dopo 39 secondi di volo interviene il sistema di autodistruzione, trasformando l'Ariane 5 e il suo carico pagante (quattro satelliti scientifici non assicurati) in quello che è stato definito "il più costoso fuoco d'artificio della storia". Il disastro avviene perché un programma del sistema di navigazione tenta di mettere un numero a 64 bit in uno spazio a 16 bit. In pratica viene ritenuto affidabile il software dell'Ariane 4 e quindi installato sull'Ariane 5. Risultato: spegnimento del sistema di guida, e trasferimento del controllo al secondo sistema di guida andato in tilt nella medesima maniera pochi millisecondi prima. Privo di guida, il vettore si autodistrugge. Nave da guerra USA va in crash grazie a Windows (1997) Nel settembre del 1997, l'incrociatore lanciamissili USS Yorktown, comandato da un avanzatissimo sistema di gestione computerizzata basato su Windows NT, va in crisi per un buffer overflow che costringe la nave a restare paralizzata in mare per due ore. Il Millennium Bug (2000) Per decenni i programmatori hanno risparmiato spazio usando solo due cifre per rappresentare gli anni. Ma all'arrivo del 2000, qualsiasi apparecchio che faccia calcoli sulle date rischia di andare in crisi perché crede di essere nel 1900. Si stima che la spesa complessiva mondiale per risolvere il Millennium Bug ammonti a 400 miliardi di dollari.
  • 11. Correttezza La correttezza di un programma è... NON QUELLA DI UN ALGORITMO Why?