Sei sulla pagina 1di 12

EECS281Winter2014

ProgrammingAssignment1
DeerHunting(PathFinding)
HuntingSeasonEndsMay13th2014,11:55pm
Overview
Inthisprogrammingassignmentyouwillimplementsomebasicalgorithmsforpathfindingin
C++,usingthemtoguideadeerhunterthroughMichiganfarmstoaBigBuck.

TheHunt
Yourhunttakesplaceonasetoffarms.Onefarmleadstooneortwoadjacentfarms,
accessiblebyaladderovertheelectricfence.Thefarmsareinsequentialorder,andareallof
thesamesize.Theterrainofafarmandtheirrepresentationsconsistsof:
'.'walkable,harvestedfields
'#'electricfences(notwalkable!)
'>'laddersupovertheelectricfence,leadingtothenextfarmuptheroad
'<'laddersdownovertheelectricfence,leadingtothepreviousfarmdowntheroad
'B'theBigBuck
'S'Grandpa'sfarm,thestartingpoint

Youcanassume,withouterrorchecking,thatthereisexactlyonebuck,andexactlyonestarting
pointamongallofthefarmsinthegametakentogether.

Yourtaskistoplanapathforthehunterfromthestarting'S'positiontotheBigBuck'B'that
doesnotcrossanyimpassable'#'electricfences,anddoesnottakethehunteroffanyofthe
farms.

Somefarmsmaynotbeenclosedbyfencesyouaretotreatfarmedgesandfencesas
impassableterrain.

Thehuntercanmovenorth,east,southorwestfromanyharvestfield'.'aswellasyour
startinglocation.Thehuntermaynotmovediagonally.Yourpathplanningprogrammust
checkthatitdoesnotmovethehunterontoelectricfences'#'.

Lettheupperleftcornerpositionofafarmhavecoordinates(0,0).Anelectricfenceladder'>'
takesthehuntertothenextfarmuptheroad(levelup).Ifthenextfarmladderisatcoordinates
(x,y)onfarmk,thehuntermovestothesamecoordinates(x,y)onfarmk+1.Youneedto
checkthatfarmk+1exists.Inasimilarmanner,thepreviousfarm('<')positiontakesthehunter
Version050514
2014RegentsoftheUniversityofMichigan

tothepreviousfarmdowntheroad(leveldown).

Theonlyneighboringpositionofaladderisthecorrespondingpositiononthefarmthatthe
ladderleadsto.Youneedtodothesamecheckforthisneighborpositionasyoudoother
neighborpositionsandtakethesameactionbasedonthepositiontypeyoufind.

Inputfileformat(TheFarms)
Theprogramgetsitsdescriptionofthefarmsfromafilethatwillbereadfromstandardinput
(cin).Thisinputfileisasimpletextfilespecifyingthelayoutofthefarms.Werequirethatyou
makeyourprogramcompatiblewithtwoinputmodes:map(M)andcoordinatelist(L).
Thereasonforhavingtwoinputmodesisthatalargepercentageoftheruntimeofyourprogram
willbespentonreadinginputorwritingoutput.Coordinatelistmodeexistssothatwecan
expressverylargegraphswithrelativelyfewlinesofafile,mapinputmodeexiststoexpress
densegraphs(onesforwhichmostofthetilesarenotjustfloorspace)inthesmallestnumber
oflines.Notethatyoushoulduseanostringstream,asdescribedinlectureanddiscussion,to
helpoptimizeyourperformancewhenwritingoutputthismakesaverysignificantruntime
difference.

Forbothinputmodes('M'and'L'):
Thefirstlineofeveryinputfilewillbeasinglecharacterspecifyingtheinputmode,'M'or'L'.
Notethatunliketheoutputmode,whichisgivenonthecommandline(seebelow),this
ispartofthefile.

ThesecondlinewillbeasingleintegerN,indicatingthesizeofeach(andevery)farmofthemap
(eachfarmisNxNinsizeandallfarmsarethesamesize).Notethatwedonotplacealimiton
themagnitudeofNneithershouldyourcode.
Thethirdlinewillbeasingleintegerindicatingthenumberoffarms.

Commentsmayalsobeincludedinanyinputfile.

Commentlinesbeginwith'//'andtheyareallowedanywhereinthefileafterthefirstthree
lines.Whendevelopingyourtestcases,itisgoodpracticetoplaceacommentonline4
describingthenatureofthefarmsinthetestcase.Anyfarmswithnoteworthycharacteristics
fortestingpurposesshouldalsobecommented.Byconvention,acommentlineidentifyingthe
farmnumberisplacedbeforethemapofthatfarm.Commentsareallowedineitherinputmode.

Additionallytheremaybeextrablank/emptylinesattheendofanyinputfileyourprogram
shouldignorethem.Ifyouseeablanklineinthefile,youmayassumethatyouhavehittheend.

Mapinputmode(M):

Forthisinputmode,thefileshouldcontainamapofeachfarm,inorder.Thefarmsare
Version050514
2014RegentsoftheUniversityofMichigan

specifiedbeginningwiththelowestfarmandworkingup.Thelowestfarmisfarm0thatisto
say,thefarmsare0indexed.

AvalidMmodeinputexamplefileforamapthathastwo4x4farm:

M
4
2
//sampleMmodeinputfilewithtwo4x4farms
//farm0
....
#...
.#..
#...
//farm1
.B..
....
...S
#.<#

Coordinatelistinputmode(L):

Thefileshould(afterthefirstthreelines)containalistofcoordinatesforatleastallnonwalkable
spacecoordinatesinthefarms.Onlyonecoordinateshouldappearonagivenline.Wedonot
requirethatthecoordinatesappearinanyparticularorder.Acoordinateisspecifiedinprecisely
thefollowingform:(row,col,farm,character).Therowandcolpositionsrangefrom0
toN1,whereNisthevaluespecifiedatthetopofthefile.Bydefault,allunspecified
coordinateswithinthefarmsareoftype'.'(floorspace)however,itisnotinvalidtoredundantly
specifythemtobeso.

Validcoordinates(foramapwiththree4x4farms):
(0,1,0,#)
(2,2,2,B)
(1,3,1,.)Whileitisvalidtospecifyawalkablespace,itisredundant!

Invalidcoordinates(foramapwiththree4x4farms):
(1,2,1,#)farm1doesnotexist!
(1,2,3,.)farm3doesnotexist!
(4,3,2,#)Rowofindex4doesnotexist!
(0,1,0,F)Fisaninvalidmapcharacter!

Version050514
2014RegentsoftheUniversityofMichigan


HereisavalidLmodeinputfilethatdescribesfarmsthatareidenticaltothosethatthesampleM
inputfiledid:
L
4
2
//sampleLmodeinputfile,two4x4farms
(1,0,0,#)
(2,1,0,#)
(3,0,0,#)
(0,1,1,B)
(2,3,1,S)
(3,0,1,#)
(3,2,1,<)
(3,3,1,#)

Routingschemes
YouaretodeveloptworoutingschemestogetfromthestartinglocationtotheBigBucklocation
tile:
Aqueuebasedroutingscheme
Astackbasedroutingscheme

Intheroutingschemeuseadatastructure(queueorstack)oflocationswithinthefarms.First,
initializethealgorithmbyaddingthestartposition'S'intothedatastructure.Then,loopthrough
thefollowingsteps:
1. Removethenextpositionfromthedatastructure.
2. Ifthepositionyoujustremovedisaladderthen:
Addthecorrespondingpositiononthefarmthattheladderleadsto.Up'>'or
down'<'afarminthesamecoordinate.Thisistheonlypositionyoucan
movetofromaladder.
else:
Addalllocationsadjacenttothelocationyoujustremovedthatareavailableto
moveinto(walkableharvestedfields,ladders,orthebigbuck).Addany
locationsthatyouareallowedtomovetofromyourpresentlocationinthe
followingorder:north,east,south,andwest.
3. Asyouaddthesespacestothedatastructure,checktoseeifanyofthemistheBig
Bucktile'B'ifso,stopelsegobacktostep1.

Donotaddspacesthathavebeenaddedtothedatastructurebefore.Rememberthat
fromawalkableharvestedfieldtile'.'oryourstartinglocation'S'youcanonlytravelnorth,east,
south,orwest.Laddersaretheonlywayofmovingbetweenfarms.

Version050514
2014RegentsoftheUniversityofMichigan

Ifthedatastructurebecomesemptybeforeyoureachthebuck'B',thesearchhasfailedand
thereisnopathtothebuck.

Note:Theonlydifferencebetweenaladderandawalkableharvestedfieldtileiswhat
positionsyouareallowedtoaddintothedatastructurewhenyouseeit.Youstillhaveto
checkthatyouhaven'tvisitedalocationbeforeaddingit.

Theprogrammustruntocompletionwithin30secondsoftotalCPUtime(user+
system).Note,inmostcases30secondsismoretimethanyoushouldneed.Seethetime
manpageformoreinformation(thiscanbedonebyenteringmantimetothecommandline).
Wemaytestyourprogramonverylargemaps(uptoseveralmillionlocations).Besureyouare
abletonavigatetotheBigBucktileinlargefarmmapswithin30seconds.Smallerfarmmaps
shouldrunMUCHfaster.

LibrariesandRestrictions
Unlessotherwisestated,youareallowedandencouragedtouseallpartsoftheC++STLand
theotherstandardheaderfilesforthisproject.Youarenotallowedtouseotherlibraries(eg:
boost,pthread,etc).YouarenotallowedtousetheC++11regularexpressionslibrary(itisnot
fullyimplementedongcc)orthethread/atomicslibraries(itspoilsruntimemeasurements).

Outputfileformat
Theprogramwillwriteitsoutputtostandardoutput(cout).Similartoinput,werequirethatyou
implementtwopossibleoutputformats.Unlikeinput,however,theoutputformatwillbe
specifiedthroughacommandlineoption'output',or'o',whichwillbefollowedbyanargument
ofMorL(MformapoutputandLforcoordinatelistoutput).Seethesectiononcommandline
argumentsbelowformoredetails.

Forbothoutputformats,youwillshowthepathyoutookfromstarttofinish.Inbothcasesyou
shouldfirstprintthenumberofrows/colsineachfarmsandthenthenumberoffarmsofthe
map.

Mapoutputmode(M):

Forthisoutputmode,youshouldprintthemapofthefarms,replacingexistingcharactersas
neededtoshowthepathyoutook.Beginningatthestartinglocation,overwritethecharactersin
yourpathwith'n','e','s','w','d'(farmdowntheroad),and'u'(farmuptheroad)to
indicatewhichtileyoumovedtonext.DonotoverwritetheBigBuck'B'attheendofthepath,
butdooverwritethe'S'atthebeginning.Forallspacesthatarenotapartofthepath,simply
reprinttheoriginalfarmmapspace.Youshoulddiscardallexistingcommentsfromtheinputfile
fortheoutputfile.However,docreatecommentstoindicatethefarmnumbersandformatthem
asshownbelow:

Version050514
2014RegentsoftheUniversityofMichigan


Thus,forthesampleinputfilespecifiedearlier,usingthequeuebasedroutingschemeandmap
(M)styleoutput,youshouldproducethefollowingoutput:

4
2
//farm0
....
#...
.#..
#...
//farm1
.Bww
...n
...n
#.<#

Usingthesameinputfilebutwiththestackbasedroutingscheme,youshouldproducethe
followingoutput:

4
2
//farm0
....
#...
.#..
#...
//farm1
eB..
n...
nwww
#.<#

Wehavehighlightedthemodificationstotheoutputinredtocallattentiontothemdonotattempt
tocoloryouroutput(thisisn'tpossible,asyouroutputmustbeaplaintextfile).

Coordinatelistoutputmode(L):

Forthisoutputmode,youshouldprintonlythecoordinatesthatmakeupthepathyoutraveled.
Youshouldprinttheminorder,from(andincluding)thestartingpositiontothe'B'(butyoushould
notprintthecoordinatefor'B').Thecoordinatesshouldbeprintedinthesameformatasthey
arespecifiedincoordinatelistinputmode(row,col,farm,character).Thecharacterof
thecoordinateshouldbe'n','e','s','w','d'or'u'toindicatespatiallywhichtileis
Version050514
2014RegentsoftheUniversityofMichigan

movedtonext.Youshoulddiscardallcommentsfromtheinputfile,butyoushouldaddone
commentonline3,justbeforeyoulistthecoordinatesofthepaththatsays//pathtaken.

Thefollowingareexamplesofcorrectoutputformatin(L)coordinatelistmodethatreflectthe
samesolutionastheMapoutputformatabove:

Forthequeuesolution:

4
2
//pathtaken
(2,3,1,n)
(1,3,1,n)
(0,3,1,w)
(0,2,1,w)

Forthestacksolution:

4
2
//pathtaken
(2,3,1,w)
(2,2,1,w)
(2,1,1,w)
(2,0,1,n)
(1,0,1,n)
(0,0,1,e)

Thereisonlyoneacceptablesolutionperroutingschemeforeachmapofthefarms.Ifnovalid
routeexists,theprogramshouldsimplyreprintthefarmswithnorouteshownforMapoutput
mode,andshouldhavenocoordinateslistedafterthe//pathtakencommentinCoordinate
listoutputmode.

Pleasenotethatthemodeofinputandoutputcanvary.Thatis,theinputmodemaybe
Coordinatemode,buttheoutputmayberequestedinMapmodeandviseversa.Theymayalso
be,butarenotguaranteedtobe,thesame.

Commandlinearguments
Yourprogramshouldtakethefollowingcasesensitivecommandlineoptions(whenwesaya
switchis"set",itmeansthatitappearsonthecommandlinewhenyoucalltheprogram):
stack,s:Ifthisswitchisset,usethestackbasedroutingscheme.
queue,q:Ifthisswitchisset,usethequeuebasedroutingscheme.
Version050514
2014RegentsoftheUniversityofMichigan

output(M|L),o(M|L):IndicatestheoutputfileformatbyfollowingtheflagwithanM
(mapformat)orL(coordinatelistformat).Iftheoutputoptionisnotspecified,defaultto
mapoutputformat(M),ifoutputisspecifiedonthecommandline,theargument(either
MorL)toitisrequired.Seetheexamplesbelowregardinguse.
help,h:Ifthisswitchisset,theprogramshouldprintabriefhelpmessagewhich
describeswhattheprogramdoesandwhateachoftheflagsare.Theprogramshould
thenexit(0)orreturn0frommain.
Note:Whenwesaystack,ors,wemeanthatcallingtheprogramwithstackdoes
thesamethingascallingtheprogramwiths.Seegetoptforhowtodothis.

Legalcommandlineargumentsmustincludeexactlyoneofstackorqueue(ortheir
respectiveshortformssorq).Ifnonearespecifiedormorethanoneisspecified,theprogram
shouldprintaninformativemessagetostandarderror(cerr)andcallexit(1).

Examplesoflegalcommandlines:
./proj1stack<infile>outfile
Thiswillruntheprogramusingthestackalgorithmandmapoutputmode.
./proj1queueoutputM<infile>outfile
Thiswillruntheprogramusingthequeuealgorithmandmapoutputmode.
./proj1stackoutputL<infile>outfile
Thiswillruntheprogramusingthestackalgorithmandcoordinatelistoutput
mode.

Notethatasdiscussedindiscussion,weareusinginputandoutputredirectionhere.
Whilewearereadingourinputfromafileandsendingoutoutputtoanotherfileinthis
case,weareNOTusingfilestreams!Theoperatingsystemmakescallstocinreadthe
inputfileanditmakescallstocoutappendtotheoutputfile.Cometoofficehoursifthisis
confusing!

Examplesofillegalcommandlines:
./proj1queues<infile>outfile
Contradictorychoiceofrouting
./proj1<infile>outfile
Youmustspecifyeitherstackorqueue

Testcases
Itisextremelyfrustratingtoturnincodethatyouare"certain"isfunctionalandthenreceive
halfcredit.Wewillbegradingforcorrectnessprimarilybyrunningyourprogramonanumberof
testcases.Ifyouhaveasinglesillybugthatcausesmostofthetestcasestofail,youwillgeta
verylowscoreonthatpartoftheprojecteventhoughyoucompleted95%ofthework.Mostof
yourgradewillcomefromcorrectnesstesting.Therefore,itisimperativethatyoutestyourcode
thoroughly.Tohelpyoudothiswewillrequirethatyouwriteandsubmitasuiteoftestcases
Version050514
2014RegentsoftheUniversityofMichigan

thatthoroughlytestyourproject.

Yourtestcaseswillbeusedtotestasetofbuggysolutionstotheproject.Partofyourgradewill
bebasedonhowmanyofthebugsareexposedbyyourtestcases.(Wesayabugisexposed
byatestcaseifthetestcasecausesthebuggysolutiontoproducedifferentoutputfroma
correctsolution.)

Eachtestcaseshouldbeaninputfilethatdescribesamapoffarmsineithermap(M)or
coordinatelist(L)format.Eachtestcasefileshouldbenamedtestn.txtwhere0<n<=15for
eachtestcase.Alltestcaseswillberuninbothqueuemodeandstackmode.Testcasesmay
havenomorethan10farms,andthesizeofafarmmaynotexceed8x8.Youmaysubmitupto
15testcases(thoughitispossibletogetfullcreditwithfarfewertestcases).Notethatthe
teststheautograderrunsonyoursolutionareNOTlimitedto10x8x8yoursolutionshouldnot
imposeanysizelimits(aslongassufficientsystemmemoryisavailable).

Errorsyoumustcheckfor
Asmallportionofyourgradewillbebasedonerrorchecking.Youmustcheckforthefollowing
errors:
Inputerrors:illegalmapcharacters.
Forcoordinatelistinputmode,youmustcheckthattherow,column,andfarmnumbers
ofeachcoordinateareallvalidpositions.
Moreorlessthanonestackorqueueonthecommandline.Youmayassumethe
commandlinewillotherwisebecorrect(thisalsomeansthatwewillnotgiveyou
charactersotherthan'M'or'L'tooutput).
Inallofthesecases,printaninformativeerrormessagetostandarderror(cerr)andcallexit(1).
Youdonotneedtocheckforanyothererrors.

Assumptionsyoumaymake

Youmayassumewewillnotputextracharactersaftertheendofalineofthemapor
afteracoordinate.
Youmayassumethatcoordinatesincoordinatelistinputmodewillbeintheformat
(row,col,farm,character).
Youmayassumethattherewillbeexactlyonestartlocation'S'andexactlyoneBigBuck
tile'B'inthemap.
Youmayassumethatwewillnotgiveyouthesamecoordinatetwiceforthecoordinate
listinputmode.
Youmayassumetheinputmodelineandtheintegerdimensionsofthefarmsonlines
twoandthreeatthebeginningoftheinputfilewillbebythemselves,withoutinterspersed
comments,andthattheywillbecorrect.

Version050514
2014RegentsoftheUniversityofMichigan

SubmissiontotheAutograder
Doallofyourwork(withallneededfiles,aswellastestcases)insomedirectoryotherthanyour
homedirectory.Thiswillbeyour"submitdirectory".Beforeyouturninyourcode,besurethat:
Youhavedeletedall.ofilesandyourexecutable(s).Typing'makeclean'shall
accomplishthis.
YourmakefileiscalledMakefile.Typing'makeRr'buildsyourcodewithouterrors
andgeneratesanexecutablefilecalledproj1.(NotethatthecommandlineoptionsR
andrdisableautomaticbuildrules,whichwillnotworkontheautograder).
YourMakefilespecifiesthatyouarecompilingwiththegccoptimizationoptionO3.This
isextremelyimportantforgettingalloftheperformancepoints,asO3canoftenspeed
upcodebyanorderofmagnitude.Youshouldalsoensurethatyouarenotsubmittinga
Makefiletotheautograderthatcompileswiththedebugflag,g,asthiswillslowyour
codedownconsiderably.Note:Ifyourcodeworkswhenyoudon'tcompilewithO3
andbreakswhenyoudo,itmeansyouhaveabuginyourcode!
Yourtestcasefilesarenamedtestn.txtandnootherprojectfilenamesbeginwithtest.
Upto15testsmaybesubmitted.
Thetotalsizeofyourprogramandtestcasesdoesnotexceed2MB.
Youdon'thaveanyunnecessaryfilesorotherjunkinyoursubmitdirectoryandyour
submitdirectoryhasnosubdirectories.
Yourcodecompilesandrunscorrectlyusingversion4.7.0oftheg++compiler.Thisis
availableontheCAENLinuxsystems(thatyoucanaccessvialogin.engin.umich.edu).
Evenifeverythingseemstoworkonanotheroperatingsystemorwithdifferentversions
ofGCC,thecoursestaffwillnotsupportanythingotherthanGCC4.7.0runningonCAEN
Linux.Note:Inordertocompilewithg++version4.7.0onCAENyoumustputthe
followingatthetopofyourMakefile:
PATH:=/usr/um/gcc4.7.0/bin:$(PATH)
LD_LIBRARY_PATH:=/usr/um/gcc4.7.0/lib64
LD_RUN_PATH:=/usr/um/gcc4.7.0/lib64

Turninallofthefollowingfiles:
Allyour.hand.ccor.cppfilesfortheproject
YourMakefile
Yourtestcasefiles

Youmustprepareacompressedtararchive(.tar.gzfile)ofallofyourfilestosubmittothe
autograder.Onewaytodothisistohaveallofyourfilesforsubmission(andnothingelse)in
onedirectory.Gointothisdirectoryandrunthiscommand:
dos2unixU*tarczf./submit.tar.gz*.cpp*.h*.cc*.cMakefiletest*.txt
Thiswillprepareasuitablefileinyourworkingdirectory.

Submityourprojectfilesdirectlytoeitherofthetwoautogradersat:
Version050514
2014RegentsoftheUniversityofMichigan

10

https://g2811.eecs.umich.edu/orhttps://g2812.eecs.umich.edu/.Youshouldloadbalance
yourselves:ifyouseethatthereare10peopleinthequeueonautograder1,submityourproject
toautograder2.Donotsubmittobothautogradersatonce!Youcansafelyignoreandoverride
anywarningsaboutaninvalidsecuritycertificate.Notethatwhentheautogradersare
turnedonandacceptingsubmissions,therewillbeanannouncement.Theautograders
areidenticalandyourdailysubmissionlimitwillbeshared(andkepttrackof)betweenthem.
Youmaysubmituptothreetimespercalendardaywithautograderfeedback.Forthispurpose,
daysbeginandendatmidnight(AnnArborlocaltime).Wewillcountonlyyourlast
submissionforyourgrade.Werealizethatitispossibleforyoutoscorehigherwithearlier
submissionstotheautograderhoweverthiswillhavenobearingonyourgrade.Westrongly
recommendthatyouusesomeformofrevisioncontrol(ie:SVN,GIT,etc)andthatyou'commit'
yourfileseverytimeyouuploadtotheautogradersothatyoucanalwaysretrieveanolder
versionofthecodeasneeded.

Pleasemakesurethatyoureadallmessagesshownatthetopsectionofyour
autograderresults!Thesemessageswillhelpexplainsomeoftheissuesyouare
having(suchaslosingpointsforhavingabadMakefile).

Grading
80pointsYourgradewillbeprimarilybasedonthecorrectnessofyouralgorithms.Your
programmusthavecorrectandworkingstackandqueuealgorithmsandsupportbothtypesof
inputandoutputmodes.Additionally:Partofyourgradewillbederivedfromtheruntime
performanceofyouralgorithms.Fastrunningalgorithmswillreceiveallpossibleperformance
points.Slowerrunningalgorithmsmayreceiveonlyaportionoftheperformancepoints.The
autogradermachineskeeptrackofthefastestruntimes(clickonViewscoreboardfromthe
autograderprojectpage).Youmaytrackyourprogressrelativetootherstudentsandinstructors
there.
20pointsTestcasecoverage(effectivenessatexposingbuggysolutions).

Gradingwillbedonebytheautograder.

Wealsoreservetherighttodeductupto5pointsforbadprogrammingstyle.

Codingstyle
Asmallportionofyourgrademaybederivedfromhavinggoodcodingstyle.Amongother
things,goodcodingstyleconsistsofthefollowing:

Cleanorganizationandconsistencythroughoutyouroverallprogram
Properpartitioningofcodeintoheaderandcppfiles
DescriptivevariablenamesandproperuseofC++idioms
Effectiveuseoflibrary(STL)code
Omittingglobals,unnecessaryliterals,orunusedlibraries
Version050514
2014RegentsoftheUniversityofMichigan

11

Effectiveuseofcomments
Reasonableformattinge.gan80columndisplay
Codereuse/noexcessivecopypastedcodeblocks

Effectiveuseofcommentsincludesstatingpreconditions,invariants,andpostconditions,
explainingnonobviouscode,andstatingbigOhcomplexitywhereappropriate.

Itisextremelyhelpfultocompileyourcodewiththegccoptions:WallWextrapedantic.This
willhelpyoucatchbugsinyourcodeearlybyhavingthecompilerpointoutwhenyouwritecode
thatiseitherofpoorstyleormightresultinbehaviorthatyouyoudidnotintend.

Empiricalefficiency
Wewillcheckforempiricalefficiencybothbymeasuringthememoryusageandrunningtimeof
yourcodeandbyreadingthecode.Wewillfocusonwhetheryouuseunnecessarytemporary
variables,whetheryoucopydatawhenasimplereferencetoitwilldo,whetheryouuseanO(n)
algorithmoranO(n2)algorithm.

Hintsandadvice

Designyourdatastructuresandworkthroughalgorithmsonpaperfirst.Drawpictures.
Considerdifferentpossibilitiesbeforeyoustartcoding.Ifyou'rehavingproblemsatthe
designstage,cometoofficehours.Afteryouhavedonesomedesignandhavea
generalunderstandingoftheassignment,rereadthisdocument.Consultitoftenduring
yourassignment'sdevelopmenttoensurethatallofyourcodeisincompliancewiththe
specification.
Alwaysthinkthroughyourdatastructuresandalgorithmsbeforeyoucodethem.Itis
importantthatyouuseefficientalgorithmsinthisprojectandinthiscourse,andcoding
beforethinkingoftenresultsininefficientalgorithms.
Ifyouareconsideringlinkedlists,besuretoreviewthelectureslidesormeasure
theirperformanceagainstvectorfirst(theoreticalcomplexitiesandactualruntime
cantelldifferentstories).
Onlyprintthespecifiedoutputtostandardoutput.
Youmayprintwhateveranydiagnosticinformationyouwishtostandarderror.However,
makesureitdoesnotscalewiththesizeofinput,oryourprogrammaynotcomplete
withinthetimelimitforlargetestcases.
Iftheprogramdoesfindaroute,besuretohavemainreturn0(orcallexit(0)).Iftheinput
isvalidbutnorouteexists,alsohavemainreturn0.
Thisisnotaneasyproject.Startitimmediately!

Havefuncoding!

Version050514
2014RegentsoftheUniversityofMichigan

12

Potrebbero piacerti anche