Assignment One Solution.pdf

4 Pages
403 Views
Unlock Document

Department
Computer Science
Course
CSCC73H3
Professor
Vassos Hadzilacos
Semester
Fall

Description
ComputerScienceC73September182013ScarboroughCampusUniversityofTorontoSolutionsforHomeworkAssignment1AnswertoQuestion1WesaythatasetAoflocationsforthesuperboxescoversasetoflocationsBofhousesifeveryelementofBiswithindistancedofsomeelementofAWerstsortLinincreasingdistancefromthestartoftheroadWemaintainasetSoflocationsforthesuperboxesandasetCofthesetofhousescoveredbySInitiallySandCarebothemptyAteachstagewelookatthersthouseinLthatisnotinCiethersthousethatisnotcoveredbyourcurrentchoiceSoflocationsforthesuperboxesletbethelocationofthishouseWeextendSbyaddingtoitthelocationdThiscoversthenotpreviouslycoveredhouseinaswellasanyotherhousethathappenstolieintheinterval2dsoweaddthelocationsofthesehousestoCandproceedinthesamemanneruntileverylocationinLiscoveredieuntilCLsortLSCwhileCLdotherstsmallestelementinLCSSdCChLh2dreturnSCorrectnessWeprovethecorrectnessofthisalgorithmusingthepromisingsetalsoknownasgreedystaysaheadapproachLetsssbetheelementsofthesetSoutputbytheabove12kalgorithmsortedinincreasingorderwhichisalsotheorderinwhichtheyareaddedtoSLetTbeanoptimalsetoflocationsforthesuperboxesandlettttbetheelementsofTinincreasingorder12mSinceTisoptimalmkAstraightforwardinductionontheiterationnumberprovesthefollowinginvariantLemma1AttheendofeachiterationofthealgorithmScoversCanddoesnotcoveranyelementinLCLemma2Foreachintegerisuchthat1imstiiProofByinductiononiForthebasisi1letbetherstelementofLBythealgorithmsd1IfstthentdandsothesetTdoesnotcovercontradictingthatTisoptimalThusst11111Fortheinductionstepassumethatstforsomeintegeri1imWewillprovethatstiii1i1SupposeforcontradictionthatstBythealgorithmwhensisaddedtoSiniterationi1i1i1i1thereisahouseinlocationsdsuchthatsdotherwisebyLemma1wouldbecoveredi1ibySattheendofiterationiSowehavetdsdstThereforethesetTdoesnotiii1i1coverthehouseinlocationcontradictingthatTisoptimalQEDWecannowprovethatSthesetoutputbythealgorithmisoptimalSupposeforcontradictionthatSisnotoptimalThenmkandthegreedyalgorithmaddsstoSiniterationm1Bythem1algorithmthereisahouseinlocationsdandsdotherwisebyLemma1wouldbem1mcoveredbySattheendofiterationmSincetsbyLemma2TdoesnotcovercontradictingmmthatTisanoptimalsetTimecomplexitySortingLcanbedoneinOnlogntimeIntheloopaconstantamountofworkisdoneforeachelementinLsothelooptakesOntimeThereforethealgorithmcanbeimplementedtoruninOnlogntimeAnswertoQuestion2aThisgreedystrategydoesnotresultinanoptimalorderingofthelesHereisacounterexampleforn2twolesp011andp992Ifweplacetheleson11221
More Less

Related notes for CSCC73H3

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit