SlideShare a Scribd company logo
$*(%+* %$$
* # 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 2010
Venugopala Rao P
 
Interaction design
Interaction designInteraction design
Interaction design
feifei2011
 
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.pdf
SANTOSMAGDALENAGUAMA
 
Introduction - Builders at Play
Introduction - Builders at PlayIntroduction - Builders at Play
Introduction - Builders at Play
Smart 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 conference
Adam Nemeth
 
Izovenezuela[1]
Izovenezuela[1]Izovenezuela[1]
Izovenezuela[1]
faceAface Comunicaciones
 
William Isaías-Derechos humanos
William Isaías-Derechos humanosWilliam Isaías-Derechos humanos
William Isaías-Derechos humanos
William Isaias
 
Roberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanosRoberto Isaias - Derechos humanos
Roberto Isaias - Derechos humanos
Roberto 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 2010
Julian 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

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx
benykoy2024
 

Recently uploaded (20)

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx01-GPON Fundamental fttx ftth basic .pptx
01-GPON Fundamental fttx ftth basic .pptx
 

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.