2017 Algorithmics Written examination
Transcript of 2017 Algorithmics Written examination
ALGORITHMICS (HESS)Written examination
Monday 6 November 2017 Reading time: 11.45 am to 12.00 noon (15 minutes) Writing time: 12.00 noon to 2.00 pm (2 hours)
QUESTION AND ANSWER BOOK
Structure of bookSection Number of
questionsNumber of questions
to be answeredNumber of
marks
A 20 20 20B 16 16 80
Total 100
• Studentsarepermittedtobringintotheexaminationroom:pens,pencils,highlighters,erasers,sharpeners,rulersandonescientificcalculator.
• StudentsareNOTpermittedtobringintotheexaminationroom:blanksheetsofpaperand/orcorrectionfluid/tape.
Materials supplied• Questionandanswerbookof26pages• Answersheetformultiple-choicequestions
Instructions• Writeyourstudent numberinthespaceprovidedaboveonthispage.• Checkthatyournameandstudent numberasprintedonyouranswersheetformultiple-choice
questionsarecorrect,andsignyournameinthespaceprovidedtoverifythis.• AllwrittenresponsesmustbeinEnglish.
At the end of the examination• Placetheanswersheetformultiple-choicequestionsinsidethefrontcoverofthisbook.
Students are NOT permitted to bring mobile phones and/or any other unauthorised electronic devices into the examination room.
©VICTORIANCURRICULUMANDASSESSMENTAUTHORITY2017
SUPERVISOR TO ATTACH PROCESSING LABEL HEREVictorian Certificate of Education 2017
STUDENT NUMBER
Letter
2017ALGORITHMICSEXAM 2
SECTION A – continued
Question 1Forextremelylargevaluesofn,whichoneofthefollowingstatementsinrelationtothetimecomplexityofanalgorithmiscorrect?A. ThebestcaserunningtimeofanalgorithmthatrunsinO(n)timecanbefasterthantheworstcase
runningtimeofanalgorithmthatrunsinO(logn)time.B. TheworstcaserunningtimeofanalgorithmthatrunsinO(n)timecanbefasterthanthebestcase
runningtimeofanalgorithmthatrunsinO(logn)time.C. AnalgorithmthatrunsinO(n)timeisalwaysslowerthananalgorithmthatrunsinO(logn)time.D. AnalgorithmthatrunsinΩ(n)timeisalwaysslowerthananalgorithmthatrunsinO(n2)time.
Question 2OnedifferencebetweentheBellman-FordandDijkstra’sshortestpathalgorithmsisthatA. Dijkstra’salgorithmrevisitsedgesofnodes.B. theBellman-Fordalgorithmrevisitsedgesofnodes.C. Dijkstra’salgorithmwillnotunderestimateshortestpathlengths,whereastheBellman-Fordalgorithm
will.D. theBellman-Fordalgorithmfailswhencomputedongraphswithnegativecycles,whereasDijkstra’s
algorithmdoesnot.
SECTION A – Multiple-choice questions
Instructions for Section AAnswerallquestionsinpencilontheanswersheetprovidedformultiple-choicequestions.Choosetheresponsethatiscorrectorthatbest answersthequestion.Acorrectanswerscores1;anincorrectanswerscores0.Markswillnotbedeductedforincorrectanswers.Nomarkswillbegivenifmorethanoneansweriscompletedforanyquestion.UsetheMasterTheoremtosolverecurrencerelationsoftheformshownbelow.
T naT n
bkn
d
n
n
c( ) =
+
>
=
if
if
1
1 wherea>0,b>1,c≥0,d≥0,k > 0
anditssolutionT nO nO n nO n
a ca c
c
cb
bba
( )( )( log )( )
loglogloglog
=
<=
ififif bb a c>
3 2017ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Question 3Considerthefollowingpseudocodeforthealgorithmf(a, b).
Algorithm f (a, b)
Inputs: a, b; both integers ≥ 0
Output: an integer ≥ 0
if (a < b)
return a
else
return f(a – b, a)
endif
Whatdoesthealgorithmfreturnwhena=2andb=3?A. 0B. 1C. 2D. 3
Use the following information to answer Questions 4 and 5.Alarge,straightshippingcanalusesaspecialsystemtoallowshipstopassthroughsafely.Forthesystemtowork,onlyoneshipcanpassthroughthecanalatatime,regardlessofwhichdirectionthatshipcomesfrom.Ifashipiscurrentlypassingthroughthecanalandanothershiparrives,thesecondshipmustwaituntilthefirstshiphasreachedtheothersidebeforeitcanproceed.Ifthereareshipswaitingoneithersideofthecanalatthesametime,theshipthatarrivedearliestisthenexttoproceed.
Question 4Whichabstractdatatype(ADT)bestmodelsthebehaviourofshipsthatwanttopassthroughthecanal?A. stackB. queueC. dictionaryD. associativearray
Question 5Themethodcurrentlyusedtomanageshipswhentheyarriveatthecanaldoesnotaccountforthecasewhentwoshipsarrive,oneoneachside,atexactlythesametime.Thiscouldbesolvedbyimplementingaheuristictoselectwhichshipwillgofirst.Tominimisethetimeittakesforshipstopassthroughthecanal,themostrelevantdataeachshipcouldprovideasinputtoaheuristicisitsA. width.B. speed.C. length.D. weight.
2017ALGORITHMICSEXAM 4
SECTION A – continued
Question 6Considerthefollowinggraphrepresentationofpseudocode.
C
B
A
OR
AND
StartingatC,inwhichorderwouldeachofthenodesbefirstexaminediftheyweretraversedusingdepth-firstsearch?(Alphabeticalorderisusedwhenthereismorethanoneoption.)A. A,AND,B,OR,CB. A,AND,OR,B,CC. C,OR,B,AND,AD. C,B,A,AND,OR
Question 7AspecialtypeofTuringmachine,M,terminatescorrectlywithoutputOwhenrunwithafiniteinput tape,T.WhichoneofthefollowingchangescanbemadetoTtoguaranteethatwhenMisrunwithT,itstillterminateswiththeidenticalanswerO?A. shorteningthetapeB. lengtheningthetapeC. addingnewsymbolstonon-blankcellsonthetapeD. addingexistingsymbolstonon-blankcellsonthetape
Question 8Givenfinitetime,aproblemthatisclassedasundecidableisknowntohaveA. analgorithmthatreturnsavalidsolution.B. analgorithmthatchecksifasolutionisvalid.C. nosinglealgorithmthatwillreturnatrueorfalsesolution.D. morethanonealgorithmthatwillreturnatrueorfalsesolution.
Question 9ChurchandTuringdefinedthecomputabilityofafunctionbyahumanandmadetheassumptionthatA. afiniteamountofspaceandtimewasavailabletothehuman.B. thealgorithmcanrecoverfromanyerrorahumanwouldmake.C. thehumanperformingthecalculationwouldmakenomistakes.D. thehumanwouldonlyneedinfinitespacetocomputethefunction,butnotinfinitetime.
5 2017ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Question 10AprofessorisworkingonaproblemandhasthoughtofanalgorithmtoverifyhersolutioninO(n)time.Withoutknowinganythingfurtherabouttheprofessor’salgorithm,whichoneofthefollowingstatementsisdefinitelytrue?A. Theproblemcanbesolvedbyanalgorithminquadratictime.B. Theproblemcanbesolvedbyanalgorithminlineartime.C. TheproblemisinclassNP.D. TheproblemisinclassP.
Question 11Claireisthinkingofawaytosolveaproblemthatisdemonstratingcombinatorialcharacteristics.Sheischoosingbetweenabrute-forceoragreedyapproach.Tofindasolutionwithlargeinputinreasonabletime,whichapproachshouldClairechooseandforwhichreason?A. brute-force,becauseitwillalwaysfindanoptimalsolutionB. greedy,becauseitwillalwaysfindanoptimalsolutionC. brute-force,becauseitmayfindanoptimalsolutionD. greedy,becauseitmayfindanoptimalsolution
Question 12Agraphalgorithmwillneedtoworkinconditionswheretheedgesandnodesalreadytraversedcannotbechecked.Cyclescanexist,alledgeshaveaweightof0andnopre-computationcanbeundertakenonthegraph.Whichoneofthefollowingwillguaranteethatasolutionwillbefound?A. best-firstsearchB. depth-firstsearchC. breadth-firstsearchD. meta-heuristicsearch
Question 13AfarmerisbreedingrabbitsthatreproduceatamonthlyratethatfollowsaFibonacciseries. Assumethatallrabbitsthatarebornwilllive.Ifthefarmerwantstoknowhowmanyrabbitsshewillhaveintwoyears’time,thesolvingstrategythatgivesthesmallestguaranteedBig-OtimecomplexityisA. simulatedannealing.B. dynamicprogramming.C. treesearchbybacktracking.D. recursivedivide-and-conquer.
2017ALGORITHMICSEXAM 6
SECTION A – continued
Question 14Considerthefollowingfunctions:
f (n)=4n2 + 6g(n)=4n2+lognh(n) = f (n) + g(n)
j(n) = f ng n
( )( )
WhatisthebestBig-Otimecomplexitydescriptionoftheasymptoticgrowthrateofh(n)andj(n),respectively?A. O(n),O(logn)
B. O(n2),O(logn)
C. O(n),O1log n
D. O(n2),O(1)
Question 15AstudentmakesthefollowingstatementsabouttheFloyd-Warshallalgorithmonagraphwithnnodes: I ItsrunningtimeisinthePcomplexityclass. II Inthebestcase,therunningtimeisΘ(n2).III Intheworstcase,therunningtimeisO(n3).IV Intheaveragecase,therunningtimeisO(nlogn). V ItmustruninΩ(n)timebecauseeverynodemustbeinspectedatleastonce.
Whichgroupofstatementsiscorrect?A. IIandIVB. IIIandIVC. I,IIandVD. I,IIIandV
Question 16
Whatvaluesofa,bandcintherecurrenceT naT n
bkn n
n
c( ) =
+
>
=42
1
1
if
if
wouldgivetherunningtimeT(n)asO(n2logn)?A. a=9, b=3, c=2B. a=9, b=2, c=3C. a=27,b=3, c=2D. a=27,b=2, c=3
7 2017ALGORITHMICSEXAM
END OF SECTION ATURN OVER
Question 17Theownerofabusinesshastakenonanumberofcontractsthatrequirehertohirenewemployees.Theseemployeeswillworkinsmallteams,withamanagerwhowillprovidedailyreportstotheowner.Astheprojectevolves,certaintasksareaddedthathavevaryinglevelsofimportance.Theownerhasdecidedtoexpandheremployeesystemtoreflecttheinclusionofthenewteams.WhichcombinationofADTswouldbethemostappropriatetorepresentthereportingstructureandthetaskswithineachteam,respectively?A. disconnectedgraph,priorityqueueB. directedgraph,priorityqueueC. weightedgraph,stackD. decisiontree,stack
Question 18Thetimecomplexityofthebestknownalgorithmtosolvefourdifferentcomputationalproblemsisgivenbelow:Problem1:O(2n)Problem2:O(n2)Problem3:O(logn)Problem4:O(nlogn)
AccordingtoCobham’sthesis,whichproblemisnotknowntobefeasible?A. Problem1B. Problem2C. Problem3D. Problem4
Question 19WhichoneofthefollowingdidSearlenotexplicitlystateregardinghisoriginalChineseRoomArgument?A. TheChinesecharacterscanbeinterpretedandreplicated.B. Theentityinsidetheroomneedstounderstandthelanguagetoproduceanoutput.C. Thelanguageusedbytheentityisfixedandeverystatementisknowninadvanceandinitsentirety.D. Theentityinsidetheroomcontainsinstructionsthat,ifgivenaninput,canproduceanappropriate
output.
Question 20OnebenefitofusingDNAcomputingasanalternativemethodofcomputationisthatitallowsforA. largeamountsofparallelprocessing.B. theself-correctionoferrorsduringcomputation.C. resultsthatcanbeeasilyinterpretedwhencomparedtothatofabinarymachine.D. largesequentialcomputingthatcanbecomputedquickly,typicallyintheorderofmilliseconds.
2017ALGORITHMICSEXAM 8
THIS pAGE IS BLANK
9 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 1 (3marks)Alocalartistisplanningtocreateaverylargemuralmadeoutofsmallpiecesofcolouredglassthatarejoinedtogether.Herrequirementsarethateachpieceofglasscannottouchthesideofanyotherpieceofglassiftheyarethesamecolour.Thereareninecoloursofglassandtheglasspiecesareallsix-sidedpolygons.
Outlineanalgorithmtheartistcouldusetocreateamuralthatmeetshercriteriainareasonableamountoftime.Aspartofyourdescription,identifyanappropriateabstractdatatype(ADT)thatcouldbeused,referringtoitsspecifications.
SECTION B
Instructions for Section BAnswerallquestionsinthespacesprovided.UsetheMasterTheoremtosolverecurrencerelationsoftheformshownbelow.
T naT n
bkn
d
n
n
c( ) =
+
>
=
if
if
1
1 wherea>0,b>1,c≥0,d≥0,k > 0
anditssolutionT nO nO n nO n
a ca c
c
cb
bba
( )( )( log )( )
loglogloglog
=
<=
ififif bb a c>
2017ALGORITHMICSEXAM 10
SECTION B – Question 2–continued
Question 2 (6marks)Simonisdocumentinganewlydiscoveredlanguage,wherewordsvaryinthenumberoflettersandvowels(‘a’,‘e’,‘i’,‘o’,‘u’).Thislanguagemarkseachvowelinoneofthreeways.Forexample,‘a’canbemarkedas‘ā’,‘ǎ’and‘â’.Simonwouldliketoproduceanalgorithm,generateWords,thathecanusetodiscoverpotentialnewwords.Whengivenaninputword,word,withoutmarkingsshownonanyvowels,generateWords(word)wouldproduceasoutputallofthepotentialwordsthatmightexistwiththevowelmarkingsincluded.
Example with one vowelInput:catOutput:cāt,cǎt,cât
Example with two vowels Input:cateOutput:cātē,cātê,cātě,cǎtē,cǎtě,cǎtê,câtē,câtě,câtê
Simonwillusethislisttoaskspeakersofthelanguageifanyofthegeneratedwordsarerealwordsintheirlanguage.
a. DescribeanalgorithmdesignpatternthatSimoncoulduseinthegenerateWords algorithmtosolvehisproblem. 3marks
11 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
b. Simonwouldalsolikeanalgorithmthattakesasinputasetofwordswithoutvowelmarkings,returningasoutputallofthepotentialwordsbasedonvowelcombinations,aswellasallofthepotentialsentencesbasedonwordorder,whereeachwordcanappearinanypositioninthesentence.
ExplainhowmodifyingthealgorithmtogenerateallpossiblesentenceswillaffectthesolvabilityofSimon’sproblem. 3marks
2017ALGORITHMICSEXAM 12
SECTION B – continued
Question 3 (6marks)Alocksmithhasforgottenthecombinationtoalockthatheowns.Thecombinationlockhasthreedials,whereeachdialhas10possiblenumbers.Allthreenumbersmustbecorrectforthelocktoopen.Anexampleisshownbelow.
0 5 9
Writeanalgorithmthatwillfindthecorrectcombination.Assumethatthefollowingfunctionsexist:• set(x, y) –setsthevalueofdialx to y
– xisthedialfromlefttoright,where0≤x≤2 – yisthenumber,where0≤y ≤9
• unlock()–willreturnTrueifthecombinationiscorrect• reset() –willresetalldialstozero
13 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 4 (4marks)Asoftwareengineerhasdesignedaprogramthatusesanumberofdifferentalgorithmswithvaryingcomplexitytosolvealargerproblem.
Discusshowvariationincomplexitycanaffecttheoverallrunningtimeoftheprogramifthealgorithmsareinsequencecomparedtoifthealgorithmsarenested,withonecallinganother.Inyourresponse,useexamplesoftimecomplexity.
Question 5 (3marks)DescribetheHaltingProblemasdefinedbytheChurch-TuringThesis.Inyourresponse,refertothedecidabilityofaproblemandhowtheHaltingProblemaffectstheabilityofaprogramtobeverified.
2017ALGORITHMICSEXAM 14
SECTION B – continued
Question 6 (6marks)‘Hilbert’s1927programcouldbeconsideredafailure.’
ExplainwhyandwriteanargumentthatshowsthatHilbert’sworkinfluencedChurchandTuring,formingthebasisoftheChurch-TuringThesis.
15 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 7 (8marks)Emergingtechnologiesmayhelpovercomesomeofthelimitsofcurrentcomputingsystems.
a. Describeonelimitthatexistsincurrentmodelsofcomputing. 2marks
b. Describeonewayaneuralnetworkcouldbeusedtoovercomecurrentlimitsofcomputation. 3marks
c. Drawadiagramofabasicneuralnetworkrepresentedasagraph,makingsuretoindicatethepurposeofeachedgeandnode. 3marks
2017ALGORITHMICSEXAM 16
SECTION B – Question 8–continued
Question 8 (10marks)Harryownsachildcarecentre.Heurgentlyneedstoknowthemedianageofallchildrenatthecentreinordertoqualifyfornewfunding.Thechildrenaresplitintotworooms,eachwithonechildcarespecialist.Thefirstroomcontains nchildrenandthesecondroomcontainsn+1children.Thespecialistineachroomknowstheorder,byage,ofallofthechildreninthatroomandcaninstantlyanswerthequestion,‘Whatistheageofthekthchildinyourroom?’
a. Writeabrute-forcealgorithmthatwouldreturnthemedianageofallofthechildreninthechildcarecentreandwouldrequireHarrytoaskthespecialistsatotalof2n+1timesfortheageofsomechildintheirroom. 5marks
17 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
b. HarryhasbeengivenanunfinisheddraftofadifferentalgorithmthatwillalsogivehimthemedianageofallofthechildrenwhencalledasSearch(0, n – 1, 0, n).BeforeHarrycompletesthealgorithm,hewantsanestimationofthetotalnumberofquestionshewouldaskthespecialists.
Algorithm Search(L1, R1, L2, R2)
Input L1: lowest rank of child in room 1 being considered
Input R1: highest rank of child in room 1 being considered
Input L2: lowest rank of child in room 2 being considered
Input R2: highest rank of child in room 2 being considered
Let n1 = R1 - L1 + 1
Let n2 = R2 - L2 + 1
Ask specialist in Room 1 for age of child L1 + n1/2 and call that m1.
Ask specialist in Room 2 for age of child L2 + n2/2 and call that m2.
if n1 equals 0
return m2
if n2 equals 0
return m1
if m1 > m2
return Search(L1, L1 + n1/2, L2 + n2/2, R2)
else
return Search(L1 + n1/2, R1, L2, L2 + n2/2)
endif
Writearecurrencerelationthatreflectstherunningtimeofthealgorithmasitiswritten. 2marks
c. AssumethatthecompletedSearchalgorithmhasthesametimecomplexityasthedraft.
IfHarry’saimistoaskasfewquestionsaspossibleofhisspecialists,wouldyourecommendabrute-forcealgorithmortheSearchalgorithm?Justifyyourrecommendation. 3marks
2017ALGORITHMICSEXAM 18
SECTION B – continued
Question 9 (5marks)Consideraconnected,weighted,undirectedgraph,G,whosesmallestedgeweightisw.Thereisonlyoneedge(u,v)inGthathasweightw.
Outlineaproofbycontradictionthatshowsthat(u,v)mustbeinanyminimalspanningtreeofG.
19 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 10 (4marks)Josephishavingabirthdaypartyforhislittlesisterandhewantstomakesureshewinstheprizeinagamethatthechildrenwillplay.Inthegame,allthechildrenattheparty,N,willsitinacircleandpasstheprizetotheirleftMtimes.AfterMpasses,thechildholdingtheprizepassesittothechildtotheleftifN>1,thenleavesthecircle,andtheprizeispassedMtimesagain.JosephwantstochooseMsothathissisteristhelastchildleftinthecircleandwinstheprize.Josephdoesnotknowyethowmanychildrenwillbecomingtotheparty.HedecidestowriteanalgorithmthatwilllethiminputM, N, P andS,whereSisthestartinglocationofhissisterandPisthestartinglocationoftheprize(0≤P < N).Thealgorithmwillreturntrueifhissisterwillwinandfalseifanyotherchildwins.
Algorithm GetWinner (M,N,P,S)
Input: M, integer, number of prize passes to the left
Input: N, integer, number of children at the start of the game
Input: P, integer, starting location of the prize
Input: S, integer, starting location of the sister
Output: true if S is the only player left, false otherwise
Let children = [0,1,...,N-1]
Let current = P
repeat N - 1 times
Let current = remainder of (current + M)/(number of children)
Remove current from children
end repeat
if children contains only S
return true
else
return false
endif
a. Josephwritesabrute-forcesearchalgorithmthatcallsalgorithmGetWinneronallpossiblecombinationsofM,N,PandStofindwinningvaluesforhissister.
AssumingthatthealgorithmGetWinnercouldbeimplementedinO(N)time,whatisthebestcaserunningtimeofJoseph’sbrute-forcesearchalgorithm?Why? 2marks
b. AssumingthatthealgorithmGetWinnercouldbeimplementedinO(N)time,istheworstcaserunningtimeofJoseph’sbrute-forcesearchalgorithmgreaterthanO(N2)?Whyorwhynot? 2marks
2017ALGORITHMICSEXAM 20
SECTION B – Question 11–continued
Question 11 (6marks)Aplanetaryspacestationispopulatedbyworkersandtheirfamilies,whereeachfamilylivesinitsownhousingdome.Domesareconnectedtooneanotherviaanextensivetunnelsystemthatcanrunformultiplekilometres,andcontainsmanyentryandexitpointstoothertunnels.Anoutbreakofavirusisrapidlyspreadingthroughthespacestation.Thevirusisspreadbetweenpeopleiftheyliveinthesamedome.Atleastonepersonfromeachdomeneedstobevaccinatedagainstthevirustohaltitsspread.Scientistshavedevelopedavaccinethatworkswhensprayedfromtheceilingofahousingdome.Theyhavealargemapoftheareawiththelocationofalldomesclearlymarked,sortedbyascendingdistancefromtheirlaboratory.Theyproposetousethefollowingalgorithmtocarryoutthevaccinations.
Algorithm Vaccinate(L)
Input: L, a list of domes sorted by distance from the
laboratory.
while L is empty
Deliver vaccinations in the first dome in L.
Remove the last element of L.
a. Theproposedalgorithmhaserrors.
Howmanyhousingdomeswillbevaccinatedusingthisalgorithmasitiswritten? 1mark
b. Writeacorrectedversionofthealgorithmthatwillallowthevaccinationtobedeliveredtoeachdomeinorderofthedome’sdistancefromthelaboratory. 2marks
21 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
c. Afterthescientistshavevaccinatedthepeopleinsomedomesusingacorrectalgorithm,theydiscoverthatvaccinatedpeoplecanspreadthevaccinetootherswithoutthespraybeingneeded.Thismeansthatanyvaccinatedpersoncanvaccinateeveryoneintheirnearestneighbouringdomesbysimplytouchingonememberofeachneighbouringdome.
WhatADTwouldbemostappropriatetomodelhousingdomesandneighbouringdomes?Assumingthatadomecanvaccinateexactlyallofitsneighbouringdomesinoneday,whattypeofalgorithmcouldbeusedwithyourselectedADTtocomputethemaximumnumberofdaysafterscientistsstopsprayinguntileveryoneinthespacestationisvaccinated?Brieflyexplainhowthistypeofalgorithmwouldwork. 3marks
2017ALGORITHMICSEXAM 22
SECTION B – Question 12–continued
Question 12 (5marks)BattleForFlagsisacomputergamewherepairsofplayerscompeteagainstoneanotherinvirtualcombat.Eachplayerinapairhasaparticularsetofskills,withthemosteffectivepairscontainingplayerswhohavecomplementaryskills.Skilllevelsarerepresentedbywholeintegers,wherelargerintegersindicatehigherabilityinthatskill.Acomplementaryratingofaskillcanthereforebedeterminedbysummingtheabsolutedifferencesbetweentheskillsoftwoplayers.Thecomplementaryrating(CR)canberepresentedas
CR( , ) | [ ] [ ] |,A B A k B k nk
n
= − >=
−
∑ 00
1
wherenisthetotalnumberofskills,AandBarearraysofplayerskillvaluesandkistheindexvalueinthosearrays.Assumeallplayershavethesamesetsofskills.Forexample,CaroistryingtodecideifsheshouldteamupwithMaxorNik.Thesearetheirskills.
k Caro Max Nik
Speed 0 10 6 10
Accuracy 1 4 8 9
Endurance 2 5 10 4
CarohasaCRof13betweenherselfandMax,andaCRof6withNik.Sheshould,therefore,pairupwithMax.BattleForFlagsisaverypopularcomputergame,withhundredsofthousandsofplayers.Playerscanaddeachotherasfriends,allowingthemtokeeptrackofpeopletheyenjoyplayingwith.Itwouldbeusefulforthegametohaveanalgorithmthatsuggeststoaplayerthemostcomplementaryplayerthatisavailabletoplaywiththeminagame,basedontheirfriends,thefriendsoftheirfriends,andsoon.Aplayerisunavailableiftheyarealreadycompetinginagame.Iftheselectedplayerisunavailable,thenextbestplayerwhoisnotinagameisselected.
a. Aplayerwhohasjustinstalledthegamewillhavenofriends.
Suggestanadditionalconditiontoincludeinthealgorithmthatwillallownewplayerswithoutfriendstoreceivecomplementaryplayersuggestions. 2marks
23 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
b. Explainhowacombinationoftreesearchandanyotheralgorithmdesignpatternscouldbeusedinthealgorithmtoreturnthebestavailablecomplementaryplayerinreasonabletime.Aspartofyourexplanation,refertoanyassumptionsthatmustbemadeabouthowplayerdataisrepresented. 3marks
Question 13 (3marks)Twofriends,JuneandDavid,arehavingaconversationaboutthepowerofalgorithmicthinkinginreal-worldscenarios.JunechallengesDavidwiththefollowing:‘Takingintoaccountthatthereareapproximately50000citiesintheworldandthattheycanbesortedinalphabeticalorder,chooseanycityintheworldanddon’ttellmeitsname.Allowmetoaskyou“yes”or“no”questionsaboutitsnameinrelationtoothercities.I’msurethatIcanfindoutwhichcityyou’vechoseninfewerthan16questions!’
StateanddescribeanalgorithmdesignpatternthatJunecanusetoguaranteethatshewillselectDavid’schosencityusingfewerthan16questions.
2017ALGORITHMICSEXAM 24
SECTION B – continued
Question 14 (4marks)Apostofficeistestinganewself-drivingdeliveryvan.Thevanstartsitsdayinadepot,whereitreceivesalistofrequeststotransportpackagesfromthedepottotheirfinaldestinations.Assumetheself-drivingvanisofasufficientlylargesizetofitallofthepackagesthatneedtobedeliveredonanygivenday,thateachlocationwillonlyhaveonepackagedeliveredtoitandthatthevanwillalwayshaveenoughtimetodeliverallofitspackages.
a. Describeanalgorithmthatwillquicklyfindaroutefortheself-drivingvanonasingleday. 2marks
b. Describeanalgorithmthatwillfindtheshortestroutefortheself-drivingvanonasingleday. 2marks
25 2017ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 15 (4marks)Harddrivesfromalargestoragedevicehavebeeninstalledincorrectly,asshowninFigure1.ThedatacannotberecoveredinitsentiretyunlessthedrivesarereorderedasshowninFigure2.Tofurthercomplicatetheissue,thesystemitselfcanonlydeactivateonedriveoutofeight,temporarily,tobemovedtoanadjacent,vacantdrivebay.Baysabove,below,totheleftortotherightareconfiguredtoreceiveswappeddrives.
HDD1 HDD2 HDD5 HDD1 HDD2 HDD3
HDD4 HDD3 HDD4 HDD5 HDD6
HDD6 HDD7 HDD8 HDD7 HDD8
Figure 1 Figure 2
Beforeaharddrivecanbemovedtothevacantdrivebay,themanagerwantstoconfirmthathecansuccessfullymovethedrivesinFigure1tomatchtheorderinFigure2.
ExplainamethodthemanagercouldusetocheckiftheharddrivesinFigure1canbereorderedtomatchFigure2.
2017ALGORITHMICSEXAM 26
END OF QUESTION AND ANSWER BOOK
Question 16 (3marks)Inasimulation,asharkishuntingafishtoeatfordinner.Thesharkandthefisharebothcontainedin asquare5×5gridmadeofcells.Boththesharkandthefishcanmoveup,down,leftandrighttoadjacentcellsinthegrid.Theycannotmovediagonally.Assumethatthesharkstartsinthecellinthebottom-leftcornerandthefishstartsinthecellinthe upper-rightcornerofthegrid.Assumealsothateachtimethesharkmovesintoacelladjacenttoitscurrentpositioninthegrid,thefishwillrandomlymoveintoacelladjacenttoitscurrentpositioninthegrid.
Explainhowtheminimaxalgorithmcanbeusedbythesharktomaximisethelikelihoodofitcatching thefish.