Tải bản đầy đủ - 0 (trang)
2 COMPUTER SCIENCE'S METHODS OF INQUIRY

2 COMPUTER SCIENCE'S METHODS OF INQUIRY

Tải bản đầy đủ - 0trang

1.2COMPUTERSCIENCE'SMETHODSOF

INQUIRY

Computerscienceisthestudyofalgorithms,butinordertostudy

algorithms,onehastoknowwhatquestionsareworthaskingaboutan

algorithmandhowtoanswerthosequestions.Threemethodsofinquiry

(approachestoposingandansweringquestions)haveprovenusefulin

computerscience.



1.2.1Design

Whenweinventedalgorithmsforsolvingthelongestsafechillingtime

problem,wewerepracticingoneofcomputerscience'smethodsof

inquiry—design.Designistheprocessofplanninghowtobuild

something.Thethingsthatcomputerscientistsdesignrangefromthe

veryabstract,suchasalgorithms,totheveryconcrete,suchas

computersthemselves.Computerscientistsalsodesignprograms,but

programmingisjustoneofmanyformsofdesignincomputerscience.

Nomatterwhatyouaredesigning,rememberthatdesignisplanningfor

building.Buildingaproductfromagoodsetofplansisstraightforward,

andtheproductusuallyperformsasexpected;buildingfrompoorplans

usuallyleadstounexpectedproblems,andtheproductusuallydoesn't

workasexpected.Themostcommonmistakecomputersciencestudents

makeistotrytowriteaprogram(i.e.,buildsomething)withoutfirsttaking

thetimetoplanhowtodoit.



1.2.2Theory

Havingdesignedalgorithmstosolvethelongestsafechillingtime

problem,onefacesanumberofnewquestions:Dothealgorithmswork

(inotherwords,dotheymeettherequirementthatanalgorithmalways

solvesitsproblem)?Whichalgorithmteststhefewestdrinksbefore

findingtherightchillingtime?

Thesearethesortsofquestionsthatcanbeansweredbycomputer

science'ssecondmethodofinquiry—theory.Theoryistheprocessof

predicting,fromfirstprinciples,howanalgorithmwillbehaveifexecuted.



Forexample,intheprevioussection,yousawargumentsforwhyboth

algorithmssolvethechillingtimeproblem.Theseargumentsillustrated

oneformoftheoreticalreasoningincomputerscience.

Foranotherexampleoftheory,considerthenumberofdrinkseach

algorithmchills.Becausethefirstalgorithmworksmethodicallyfrom

minimalchillinguptojustbeyondthelongestsafechillingtime,in

incrementsofthemarginoferror,itrequireschillinganumberofdrinks

proportionaltothelongestsafechillingtime.Thesecondalgorithm,on

theotherhand,eliminateshalfthepossiblechillingtimeswitheachdrink.

Atthebeginningofthealgorithm,thepossiblechillingtimesrangefrom0

tothetimeknowntobetoolong.Buttestingthefirstdrinkreducesthe

setofpossibletimestoeitherthelowhalforthehighhalfofthisrange;

testingaseconddrinkcutsthishalfinhalfagain,thatis,leavesonlyone

quarteroftheoriginalpossibilities.Therangeofpossibletimeskeeps

halvingwitheveryadditionaldrinktested.Toseeconcretelywhatthis

means,supposeyoustartthisalgorithmknowingthattwohoursistoo

long,andwithamarginoferrorofoneminute.Afterchillingonedrink,

youknowthelongestsafechillingtimetowithinonehour,andaftertwo

drinkstowithin30minutes.Afteratotalofonlysevendrinks,youwill

knowexactlywhatthelongestsafechillingtimeis![3]Bycomparison,

aftersevendrinks,thefirstalgorithmwouldhavejusttriedchillingfor

sevenminutes,atimethatisprobablyfartooshort.Asthisexample

illustrates,theoreticalanalysissuggeststhatthesecondalgorithmwill

generallyusefewerdrinksthanthefirst.However,thetheoretical

analysisalsoindicatesthatifthelongestsafechillingtimeisveryshort,

thenthefirstalgorithmwillusefewerdrinksthanthesecond.Theorythus

producedbothageneralcomparisonbetweenthealgorithms,andinsight

intowhenthegeneralruledoesnothold.

Theoryallowsyoutolearnalotaboutanalgorithmwithoutever

executingit.Atfirstglance,itissurprisingthatitispossibleatalltolearn

thingsaboutanalgorithmwithoutexecutingit.However,thingsone

learnsthiswayareamongthemostimportantthingstoknow.Precisely

becausetheyareindependentofhowitisexecuted,thesearethe

propertiesthataffecteveryimplementationofthealgorithm.Forexample,

inshowingtheoreticallythatthelongestsafechillingtimealgorithmsare



correct,weshowedthatanyonewhocarriesthemoutfaithfullywillfinda

correctchillingtime,regardlessofwhatfreezer,drink,andmarginoferror

theyuse,regardlessofwhethertheycarryoutthealgorithmsbyhandor

programsomeroboticfreezertodoitforthem,etc.Incontrast,properties

thatdodependonhowanalgorithmisexecutedarelikelytoapplyonlyto

oneimplementationoruser.



1.2.3EmpiricalAnalysis

Thelongestsafechillingtimeproblemalsoraisesquestionsthatcan'tbe

answeredbytheory.Forexample,isthelongestsafechillingtimefora

givenfreezer,drink,andmarginoferroralwaysthesame?Ormightthe

freezerchillmoreorlessefficientlyonsomedaysthanonothers?This

typeofquestion,whichdealswithhowalgorithmsinteractwiththe

physicalworld,canbeansweredbycomputerscience'sthirdmethodof

inquiry—empiricalanalysis.Empiricalanalysisistheprocessoflearning

throughobservationandexperiment.Forexample,considerhowyou

couldanswerthenewquestionthroughanexperiment.

Evenbeforedoingtheexperiment,youprobablyhavesomebelief,or

hypothesis,abouttheanswer.Forexample,theauthors'experiencewith

freezersleadsustoexpectthatlongestsafechillingtimeswon'tchange

fromdaytoday(butwehaven'tactuallytriedtheexperiment).The

experimentitselfteststhehypothesis.Fortheauthors'hypothesis,it

mightproceedasfollows:Onthefirstdayoftheexperiment,determine

thelongestsafechillingtimeforyourfreezer,drink,andmarginoferror.

Onthesecondday,checkthatthistimeisstillthelongestsafechilling

time(forexample,bychillingonedrinkforthattime,andanotherforthat

timeplusthemarginoferror,toseeiftheseconddrinkstartstofreeze

butthefirstdoesn't).Ifthefirstday'slongestsafechillingtimeisnotthe

longestsafechillingtimeonthesecondday,thenyouhaveproventhe

hypothesisfalseandthesafechillingtimedoeschangefromdaytoday.

Ontheotherhand,ifthefirstday'slongestsafechillingtimeisstillthe

longestsafechillingtimeonthesecondday,itreinforcesthehypothesis.

Butnotethatitdoesnotprovethehypothesistrue—youmighthavejust

gottenluckyandhadtwodaysinarowwiththesamelongestsafe

chillingtime.Youshouldthereforetestthechillingtimeagainonathird



day.Similarly,youmightwanttocontinuetheexperimentforafourthday,

afifthday,andmaybeevenlonger.Themoredaysonwhichthelongest

safechillingtimeremainsthesame,themoreconfidentyoucanbethat

thehypothesisistrue.Eventuallyyouwillbecomesoconfidentthatyou

won'tfeelanymoreneedtoexperiment(assumingthelongestsafe

chillingtimealwaysstaysthesame).However,youwillneverbeableto

saywithabsolutecertaintythatyouhaveproventhehypothesis—thereis

alwaysachancethatthelongestsafechillingtimecanchange,butjust

byluckitdidn'tduringyourexperiment.

Thisexampleillustratesanimportantcontrastbetweentheoryand

empiricalanalysis:theorycanprovewithabsolutecertaintythata

statementistrue,butonlybymakingsimplifyingassumptionsthatleave

some(small)doubtaboutwhetherthestatementisrelevantinthe

physicalworld.Empiricalanalysiscanshowthatinmanyinstancesa

statementistrueinthephysicalworld,butonlybyleavingsome(small)

doubtaboutwhetherthestatementisalwaystrue.Justasinother

sciences,themorecarefullyoneconductsanexperiment,theless

chancethereisofreachingaconclusionthatisnotalwaystrue.

Computerscientists,therefore,designandcarryoutexperiments

accordingtothesamescientificmethodthatotherscientistsuse.



Exercises

Ingeneral,analgorithmthattestsfewerdrinkstosolvethesafe

chillingproblemisbetterthanonethattestsmoredrinks.Buton

theotherhand,youmightwanttominimizethenumberofdrinks

thatfreezewhilesolvingtheproblem(sincefrozendrinksget

1.8.

messy).Whatisthegreatestnumberofdrinksthateachofour

algorithmscouldcausetofreeze?Isthealgorithmthatisbetterby

thismeasurethesameasthealgorithmthatisbetterintermsof

thenumberofdrinksittests?

1.9.



Apieceoffolkwisdomsays,"Droppedtoastalwayslandsbuttersidedown."Trytodoanexperimenttotestthishypothesis.

Throughoutthischapter,wehavemadeanumberofassertions

aboutchillingdrinksinfreezers(e.g.,thatfrozendrinksburst,



1.10. etc.).Pickoneormoreoftheseassertions,andtrytodo

experimentstotestthem.Buttakeresponsibilityforcleaningup

anymessafterwards!

[3]Mathematically,thisalgorithmchillsanumberofdrinksproportionalto

thelogarithmofthelongestsafechillingtime.







1.3CONCLUDINGREMARKS

Computerscienceisthesciencethatstudiesalgorithms.Analgorithmis

aprocessforsolvingaproblem.Tobeanalgorithm,aprocessmust:

Beunambiguous.

Solvetheprobleminafinitenumberofsteps.

Inordertobesolvedbyanalgorithm,aproblemmustbedefined

preciselyenoughforapersontobeabletotellwhetheraproposed

answerisrightorwrong.Inorderforittobeworthwhilesolvingaproblem

withanalgorithm,theproblemusuallyhastobegeneralenoughtohave

anumberofdifferentinstances.

Computerscientistsusethreemethodsofinquirytostudyalgorithms:

design,theory,andempiricalanalysis.

Figure1.1illustratestherelationshipsbetweenalgorithms,design,

theory,andempiricalanalysis.Algorithmsarethefield'scentralconcern

—theyarethereasoncomputerscientistsengageinanyofthemethods

ofinquiry.Designcreatesalgorithms.Theorypredictshowalgorithmswill

behaveunderidealcircumstances.Empiricalanalysismeasureshow

algorithmsbehaveinparticularrealsettings.



Figure1.1:Algorithmsand

methodsofinquiryincomputerscience.



Eachmethodofinquiryalsointeractswiththeothers.Afterdesigninga

program,computer,oralgorithm,thedesignerneedstotestittoseeifit

behavesasexpected;thistestingisanexampleofempiricalanalysis.

Empiricalanalysisinvolvesexperiments,whichmustbeperformedon

concreteprogramsorcomputers;creatingthesethingsisanexampleof

design.Designersofprograms,computers,oralgorithmsmustchoose

thedesignthatbestmeetstheirneeds;theoryguidestheminmakingthis

choice.Theoreticalproofsandderivationsoftenhavestructuresalmost

identicaltothoseofthealgorithmtheyanalyze—inotherwords,a

productofdesignalsoguidestheoreticalanalysis.Empiricalanalysis

testshypothesesabouthowaprogramorcomputerwillbehave;these

hypothesescomefromtheoreticalpredictions.Theoryinevitablyrequires

simplifyingassumptionsaboutalgorithmsinordertomakemathematical

analysistractable,yetitmustavoidsimplificationsthatmakeresults

unrealistic;empiricalanalysisshowswhichsimplificationsarerealistic

andwhicharen't.

Therestofthistextexploresmorefullytheinteractionsbetween

algorithms,design,theory,andempiricalanalysis.Thegoalistoleave

youwithabasicbutnonethelessrealabilitytoengageinallthree

methodsofinquiryincomputing.Inthenextchapter,weintroducesome

fundamentalconceptsinalgorithmdesign.Thetwochaptersafterthat

providesimilarintroductionstotheoryandempiricalanalysis.







1.4FURTHERREADING

Formoreonthemeaningandhistoryoftheword"algorithm,"seeSection

1.1of:

DonaldKnuth,FundamentalAlgorithms(TheArtofComputer

Programming,Vol.1),Addison-Wesley,1973.

Formoreonhowthefield(or,assomewouldhaveit,fields)ofcomputer

sciencedefinesitself,see:

PeterDenningetal.,"ComputingasaDiscipline,"

CommunicationsoftheACM,Jan.1989.

Thethreemethodsofinquirythatwedescribedinthischapterare

essentiallythethree"paradigms"ofcomputersciencefromthisreport.







Tài liệu bạn tìm kiếm đã sẵn sàng tải về

2 COMPUTER SCIENCE'S METHODS OF INQUIRY

Tải bản đầy đủ ngay(0 tr)

×