SlideShare a Scribd company logo
1 of 31
Download to read offline
$*(%+* %$$
* # 0* %$(%#)
%$+**
 (*#$*%*( $ $( $$
%#+*( $
D2@ 1 ?
,$+(#(8#($#!'-(#
J  --(#A2C
! (-+(#$('##!$)((# #!$ ,(-
! (-+('#!'!$  #(!'
D2? ')(
;3888:(('+ ) *)
D2@ ? @
# !'('
J #!!$# !''(#
J !$#*-#)$#!!' '
J  $-#) (#$() !(
,''
J -'! $#!!$# !'
'(# $-#) ' 
$#!!#$(
''!('(,(##
J #((#!#( '
#)(!( #*- ()'
$# !'('
,!1'##*
%## $ )*(* , $)
D2@ ? A
#!!''!('('
J #)'!##($# !(#'# *(#
$#!!
 ()#((!#'((
 ()'+ ('($
 ''#)( (#$#!0!##)($$
-#)(#(#('
%-%) *%#(*%;388891
D2@ ? B
+(# ('#-(#
#(+
'$'
 #+#-#)((#  /
%$ $%+((%(## $! )
D2@ ? C
'#!$)((#(# $)'((+# 
++ *
Experimental devices that help us to understand
something that has happened or to predict the future
 $(!.(#!# '
(('( !# '
!) (#!# '
%#+** %$%)
D2@ ? D
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
(#?@2?
(#C2B: !)(#';
,$* $%(%/4) *+(
D2@ ? E
'#!$)((#(# $)'((+# 
++ *
Experimental devices that help us to understand
something that has happened or to predict the future
    
(('( !# '
!) (#!# '
%#+** %$%)
D2@ ? F
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
* )$* # 0* %$%1
 An objective function that is to be maximized or
minimized, e.g.,
J Minimize time spent traveling from New York to Boston
A set of constraints (possibly empty) that must be
honored, e.g.,
J Cannot spend more than $100
J Must be in Boston before 5:00PM
D2@ ? G
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
$)!(%#)
D2@ ? ?
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
$)!(%#
#)* !('((0'#('!,!)!
+($'((-#)-
#)+#)  (#(!#'()(-#)-
 #+#-#)##'+'()(#(+(#
*/
+#*('
J 7?$'$# !
J #()#)'#(# $'$# !
D2@ ? ??
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
/ )*6,%( * $)!(%#
D2@ ? ?@
Images © sources unknown. All rights reserved. This content is excluded from our Creative
Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
(!'$'(-$0  
$'#!!#((!'+((#( 
+(##!#(
*(#00# (0$'('('(#
*  (!'2 !(#(*(#'
(!
*(#00# (0')'(#(+(
##((!'(2  0(!  '(2
 0(!  '#((
859 $)!(%#2%(# 0
D2@ ? ?A
859 $)!(%#2%(# 0
D2@ ? ?B
?2)!( $#'' #!(#'#(!'2(
'(#'-0( ')'('#('(#(!'2''
 ($#+'(2
@2!#* #(#!(#'+#'(#( )('
,'( #++(2
A2#!(!#!(#'##'-#
+#'* )'( '(2
(+*%(%( *#
D2@ ? ?C
#+'$#+'(/

J *(#00# (0')'(#(+(##(
(!'(2  0(!  '(2  0(! 
'#((
 #+!-$#'' (* )' */
J '!-(-)!''$'(
 ('
#,!$ 0(?(!'(###'#!0(
$#+'('#'./
J ?0@DE0DC0D0@@F0@@G0B?0BGD0EA0@C0AED
*$%*(* 
 
D2@ ? ?D
'0#
7?$'$# !'( -,$#(
)(#4('$
( +)* $*+ 1
D2@ ? ?E
while knapsack not full
put “best” available item in knapsack
)(+(#''(!/
J #'(* ) 
J '(,$'*
J '(* )7)('
(/%( *#(* *($* ,
D2@ ? ?F
#)#)((#'(#+(#
!
#)#+#+!)-#)
* )(##'0220
-#) #)('!#(
$$ '
)(-#)* #
)(0220-#)#4(+(
(##')!!#(EC
 #'
##'+((#('
$'$# !
$.#
D2@ ? ?G
(4' ##($#!((+)'(#+(
(##
$+
D2@ ? @
              
 ) FG G A C G EG G ?
 #' ?@A ?CB @CF ACB ADC ?C GC ?GC
))%%
class Food(object):
def __init__(self, n, v, w):
self.name = n
self.value = v
self.calories = w
def getValue(self):
return self.value
def getCost(self):
return self.calories
def density(self):
return self.getValue()/self.getCost()
def __str__(self):
return self.name + ': ' + str(self.value)
+ ', ' + str(self.calories) + ''
D2@ ? @?
+ $+%%%)
def buildMenu(names, values, calories):
names, values, calories lists of same length.
name a list of strings
values and calories lists of numbers
returns list of Foods
menu = []
for i in range(len(values)):
menu.append(Food(names[i], values[i],
calories[i]))
return menu
D2@ ? @@
##$** %$%. (/
def greedy(items, maxCost, keyFunction):
Assumes items a list, maxCost = 0,
keyFunction maps elements of items to numbers
itemsCopy = sorted(items, key = keyFunction,
reverse = True)
result = []
totalValue, totalCost = 0.0, 0.0
for i in range(len(itemsCopy)):
if (totalCost+itemsCopy[i].getCost()) = maxCost:
result.append(itemsCopy[i])
totalCost += itemsCopy[i].getCost()
totalValue += itemsCopy[i].getValue()
return (result, totalValue)
D2@ ? @A
%( *#   $/
def greedy(items, maxCost, keyFunction):
itemsCopy = sorted(items, key = keyFunction,
reverse = True)
result = []
totalValue, totalCost = 0.0, 0.0
for i in range(len(itemsCopy)):
if (totalCost+itemsCopy[i].getCost()) = maxCost:
result.append(itemsCopy[i])
totalCost += itemsCopy[i].getCost()
totalValue += itemsCopy[i].getValue()
return (result, totalValue)
D2@ ? @B
) $(/
def testGreedy(items, constraint, keyFunction):
taken, val = greedy(items, constraint, keyFunction)
print('Total value of items taken =', val)
for item in taken:
print(' ', item)
D2@ ? @C
) $(/
def testGreedys(maxUnits):
print('Use greedy by value to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits, Food.getValue)
print('nUse greedy by cost to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits,
lambda x: 1/Food.getCost(x))
print('nUse greedy by density to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits, Food.density)
testGreedys(800)
D2@ ? @D
/
!)'(#(#-!#)')(#'
J lambda H?0@03I1H,$''#I
J ()')(##)!('
*--0'
#'' (#+(!.#!$ ( !,$''#'
#4(9)'def '(
#
D2@ ? @E
) $(/
def testGreedys(foods, maxUnits):
print('Use greedy by value to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits, Food.getValue)
print('nUse greedy by cost to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits,
lambda x: 1/Food.getCost(x))
print('nUse greedy by density to allocate', maxUnits,
'calories')
testGreedy(foods, maxUnits, Food.density)
names = ['wine', 'beer', 'pizza', 'burger', 'fries',
'cola', 'apple', 'donut', 'cake']
values = [89,90,95,100,90,79,50,10]
calories = [123,154,258,354,365,150,95,195]
foods = buildMenu(names, values, calories)
testGreedys(foods, 750)
)#
D2@ ? @F
%)# # -5#$(! 6#'#4( +-'
-  # -#$(! '# )(#
 '--'(- +-'+/
J -('(-':##'0?;
/ ($*$)-()1
D2@ ? @G
'-(#!$ !(
#!$)((# -(
)(#'#( +-'- ('('# )(#
J #4(*#+#+##($$#,!(#'
 (,( ()+4  ##(() -#$(! 
'# )(#'
(%)$%$)%(/
D2@ ? A
MIT OpenCourseWare
https://ocw.mit.edu
6.0002 Introduction to Computational Thinking and Data Science
Fall 2016
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

More Related Content

Similar to MIT6_0002F16_lec1.pdf

Gate ee previous year papers 1992 2010
Gate ee previous year papers 1992   2010Gate ee previous year papers 1992   2010
Gate ee previous year papers 1992 2010Venugopala Rao P
 
Interaction design
Interaction designInteraction design
Interaction designfeifei2011
 
Psy4020 résumé chapitre 14 A-2013
Psy4020 résumé chapitre 14 A-2013 Psy4020 résumé chapitre 14 A-2013
Psy4020 résumé chapitre 14 A-2013 Martinsky Desjardins
 
Actualización Curricular 2010.pdf
Actualización Curricular 2010.pdfActualización Curricular 2010.pdf
Actualización Curricular 2010.pdfSANTOSMAGDALENAGUAMA
 
Introduction - Builders at Play
Introduction - Builders at PlayIntroduction - Builders at Play
Introduction - Builders at PlaySmart in Public
 
“Innovación para el empoderamiento de la ciudadanía a través de las tic”
“Innovación para el empoderamiento de la ciudadanía a través de las tic”“Innovación para el empoderamiento de la ciudadanía a través de las tic”
“Innovación para el empoderamiento de la ciudadanía a través de las tic”Noé G. Montuenga
 
Nearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceNearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceAdam Nemeth
 
William Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaias
 
Roberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias
 
Arduino notebook v1-1
Arduino notebook v1-1Arduino notebook v1-1
Arduino notebook v1-1Anil Yadav
 
Slimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesSlimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesJos Arets
 
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1Ioannis Asmis
 
WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010Julian Dolby
 
Prez et references delphine monnier
Prez et references delphine monnierPrez et references delphine monnier
Prez et references delphine monnierConsultante coach
 

Similar to MIT6_0002F16_lec1.pdf (20)

Gate ee previous year papers 1992 2010
Gate ee previous year papers 1992   2010Gate ee previous year papers 1992   2010
Gate ee previous year papers 1992 2010
 
Interaction design
Interaction designInteraction design
Interaction design
 
English
EnglishEnglish
English
 
Psy4020 résumé chapitre 14 A-2013
Psy4020 résumé chapitre 14 A-2013 Psy4020 résumé chapitre 14 A-2013
Psy4020 résumé chapitre 14 A-2013
 
Actualización Curricular 2010.pdf
Actualización Curricular 2010.pdfActualización Curricular 2010.pdf
Actualización Curricular 2010.pdf
 
Job seekers 2
Job seekers 2Job seekers 2
Job seekers 2
 
Introduction - Builders at Play
Introduction - Builders at PlayIntroduction - Builders at Play
Introduction - Builders at Play
 
“Innovación para el empoderamiento de la ciudadanía a través de las tic”
“Innovación para el empoderamiento de la ciudadanía a través de las tic”“Innovación para el empoderamiento de la ciudadanía a través de las tic”
“Innovación para el empoderamiento de la ciudadanía a través de las tic”
 
Nearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceNearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conference
 
Izovenezuela[1]
Izovenezuela[1]Izovenezuela[1]
Izovenezuela[1]
 
#ThisIsHappening
#ThisIsHappening#ThisIsHappening
#ThisIsHappening
 
William Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaías-Derechos humanos
William Isaías-Derechos humanos
 
Roberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanos
 
Arduino notebook v1-1
Arduino notebook v1-1Arduino notebook v1-1
Arduino notebook v1-1
 
APP Panacea o Ilusión
APP Panacea o IlusiónAPP Panacea o Ilusión
APP Panacea o Ilusión
 
Slimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesSlimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisaties
 
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1
586-ΑΣΜΗΣ-ΙΩΑΝΝΗΣ1
 
Decimals
DecimalsDecimals
Decimals
 
WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010
 
Prez et references delphine monnier
Prez et references delphine monnierPrez et references delphine monnier
Prez et references delphine monnier
 

Recently uploaded

electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.benjamincojr
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashidFaiyazSheikh
 
Introduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AIIntroduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AISheetal Jain
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdfKamal Acharya
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemSampad Kar
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesRashidFaridChishti
 
Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...IJECEIAES
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological universityMohd Saifudeen
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docxrahulmanepalli02
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdfAlexander Litvinenko
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2T.D. Shashikala
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Nitin Sonavane
 
Low Altitude Air Defense (LAAD) Gunner’s Handbook
Low Altitude Air Defense (LAAD) Gunner’s HandbookLow Altitude Air Defense (LAAD) Gunner’s Handbook
Low Altitude Air Defense (LAAD) Gunner’s HandbookPeterJack13
 

Recently uploaded (20)

electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Introduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AIIntroduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AI
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Microkernel in Operating System | Operating System
Microkernel in Operating System | Operating SystemMicrokernel in Operating System | Operating System
Microkernel in Operating System | Operating System
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...Performance enhancement of machine learning algorithm for breast cancer diagn...
Performance enhancement of machine learning algorithm for breast cancer diagn...
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
Module-III Varried Flow.pptx GVF Definition, Water Surface Profile Dynamic Eq...
 
Low Altitude Air Defense (LAAD) Gunner’s Handbook
Low Altitude Air Defense (LAAD) Gunner’s HandbookLow Altitude Air Defense (LAAD) Gunner’s Handbook
Low Altitude Air Defense (LAAD) Gunner’s Handbook
 

MIT6_0002F16_lec1.pdf

  • 1. $*(%+* %$$ * # 0* %$(%#) %$+** (*#$*%*( $ $( $$ %#+*( $ D2@ 1 ?
  • 2. ,$+(#(8#($#!'-(# J --(#A2C ! (-+(#$('##!$)((# #!$ ,(- ! (-+('#!'!$ #(!' D2? ')( ;3888:(('+ ) *) D2@ ? @
  • 3. # !'(' J #!!$# !''(# J !$#*-#)$#!!' ' J $-#) (#$() !( ,'' J -'! $#!!$# !' '(# $-#) ' $#!!#$( ''!('(,(## J #((#!#( ' #)(!( #*- ()' $# !'(' ,!1'##* %## $ )*(* , $) D2@ ? A
  • 4. #!!''!('(' J #)'!##($# !(#'# *(# $#!! ()#((!#'(( ()'+ ('($ ''#)( (#$#!0!##)($$ -#)(#(#(' %-%) *%#(*%;388891 D2@ ? B
  • 5. +(# ('#-(# #(+ '$' #+#-#)((# / %$ $%+((%(## $! ) D2@ ? C
  • 6. '#!$)((#(# $)'((+# ++ * Experimental devices that help us to understand something that has happened or to predict the future $(!.(#!# ' (('( !# ' !) (#!# ' %#+** %$%) D2@ ? D Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 8. '#!$)((#(# $)'((+# ++ * Experimental devices that help us to understand something that has happened or to predict the future (('( !# ' !) (#!# ' %#+** %$%) D2@ ? F Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 9. * )$* # 0* %$%1 An objective function that is to be maximized or minimized, e.g., J Minimize time spent traveling from New York to Boston A set of constraints (possibly empty) that must be honored, e.g., J Cannot spend more than $100 J Must be in Boston before 5:00PM D2@ ? G Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 10. $)!(%#) D2@ ? ? Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 11. $)!(%# #)* !('((0'#('!,!)! +($'((-#)- #)+#) (#(!#'()(-#)- #+#-#)##'+'()(#(+(# */ +#*(' J 7?$'$# ! J #()#)'#(# $'$# ! D2@ ? ?? Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 12. / )*6,%( * $)!(%# D2@ ? ?@ Images © sources unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use.
  • 13. (!'$'(-$0 $'#!!#((!'+((#( +(##!#( *(#00# (0$'('('(# * (!'2 !(#(*(#' (! *(#00# (0')'(#(+( ##((!'(2 0(! '(2 0(! '#(( 859 $)!(%#2%(# 0 D2@ ? ?A
  • 15. ?2)!( $#'' #!(#'#(!'2( '(#'-0( ')'('#('(#(!'2'' ($#+'(2 @2!#* #(#!(#'+#'(#( )(' ,'( #++(2 A2#!(!#!(#'##'-# +#'* )'( '(2 (+*%(%( *# D2@ ? ?C
  • 16. #+'$#+'(/ J *(#00# (0')'(#(+(##( (!'(2 0(! '(2 0(! '#(( #+!-$#'' (* )' */ J '!-(-)!''$'( (' #,!$ 0(?(!'(###'#!0( $#+'('#'./ J ?0@DE0DC0D0@@F0@@G0B?0BGD0EA0@C0AED *$%*(* D2@ ? ?D
  • 17. '0# 7?$'$# !'( -,$#( )(#4('$ ( +)* $*+ 1 D2@ ? ?E
  • 18. while knapsack not full put “best” available item in knapsack )(+(#''(!/ J #'(* ) J '(,$'* J '(* )7)(' (/%( *#(* *($* , D2@ ? ?F
  • 19. #)#)((#'(#+(# ! #)#+#+!)-#) * )(##'0220 -#) #)('!#( $$ ' )(-#)* # )(0220-#)#4(+( (##')!!#(EC #' ##'+((#(' $'$# ! $.# D2@ ? ?G
  • 20. (4' ##($#!((+)'(#+( (## $+ D2@ ? @ ) FG G A C G EG G ? #' ?@A ?CB @CF ACB ADC ?C GC ?GC
  • 21. ))%% class Food(object): def __init__(self, n, v, w): self.name = n self.value = v self.calories = w def getValue(self): return self.value def getCost(self): return self.calories def density(self): return self.getValue()/self.getCost() def __str__(self): return self.name + ': ' + str(self.value) + ', ' + str(self.calories) + '' D2@ ? @?
  • 22. + $+%%%) def buildMenu(names, values, calories): names, values, calories lists of same length. name a list of strings values and calories lists of numbers returns list of Foods menu = [] for i in range(len(values)): menu.append(Food(names[i], values[i], calories[i])) return menu D2@ ? @@
  • 23. ##$** %$%. (/ def greedy(items, maxCost, keyFunction): Assumes items a list, maxCost = 0, keyFunction maps elements of items to numbers itemsCopy = sorted(items, key = keyFunction, reverse = True) result = [] totalValue, totalCost = 0.0, 0.0 for i in range(len(itemsCopy)): if (totalCost+itemsCopy[i].getCost()) = maxCost: result.append(itemsCopy[i]) totalCost += itemsCopy[i].getCost() totalValue += itemsCopy[i].getValue() return (result, totalValue) D2@ ? @A
  • 24. %( *# $/ def greedy(items, maxCost, keyFunction): itemsCopy = sorted(items, key = keyFunction, reverse = True) result = [] totalValue, totalCost = 0.0, 0.0 for i in range(len(itemsCopy)): if (totalCost+itemsCopy[i].getCost()) = maxCost: result.append(itemsCopy[i]) totalCost += itemsCopy[i].getCost() totalValue += itemsCopy[i].getValue() return (result, totalValue) D2@ ? @B
  • 25. ) $(/ def testGreedy(items, constraint, keyFunction): taken, val = greedy(items, constraint, keyFunction) print('Total value of items taken =', val) for item in taken: print(' ', item) D2@ ? @C
  • 26. ) $(/ def testGreedys(maxUnits): print('Use greedy by value to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, Food.getValue) print('nUse greedy by cost to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, lambda x: 1/Food.getCost(x)) print('nUse greedy by density to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, Food.density) testGreedys(800) D2@ ? @D /
  • 27. !)'(#(#-!#)')(#' J lambda H?0@03I1H,$''#I J ()')(##)!(' *--0' #'' (#+(!.#!$ ( !,$''#' #4(9)'def '( # D2@ ? @E
  • 28. ) $(/ def testGreedys(foods, maxUnits): print('Use greedy by value to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, Food.getValue) print('nUse greedy by cost to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, lambda x: 1/Food.getCost(x)) print('nUse greedy by density to allocate', maxUnits, 'calories') testGreedy(foods, maxUnits, Food.density) names = ['wine', 'beer', 'pizza', 'burger', 'fries', 'cola', 'apple', 'donut', 'cake'] values = [89,90,95,100,90,79,50,10] calories = [123,154,258,354,365,150,95,195] foods = buildMenu(names, values, calories) testGreedys(foods, 750) )# D2@ ? @F
  • 29. %)# # -5#$(! 6#'#4( +-' - # -#$(! '# )(# '--'(- +-'+/ J -('(-':##'0?; / ($*$)-()1 D2@ ? @G
  • 30. '-(#!$ !( #!$)((# -( )(#'#( +-'- ('('# )(# J #4(*#+#+##($$#,!(#' (,( ()+4 ##(() -#$(! '# )(#' (%)$%$)%(/ D2@ ? A
  • 31. MIT OpenCourseWare https://ocw.mit.edu 6.0002 Introduction to Computational Thinking and Data Science Fall 2016 For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.