Page 1
ALGORITHMICS (HESS)Written examination
Tuesday 19 November 2019 Reading time: 3.00 pm to 3.15 pm (15 minutes) Writing time: 3.15 pm to 5.15 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• Questionandanswerbookof29pages• 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.
©VICTORIANCURRICULUMANDASSESSMENTAUTHORITY2019
SUPERVISOR TO ATTACH PROCESSING LABEL HEREVictorian Certificate of Education 2019
STUDENT NUMBER
Letter
Page 2
2019ALGORITHMICSEXAM 2
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
THIS PAGE IS BLANK
Page 3
3 2019ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 1Astack,S,containstheelements
S=[0,8,18,12,31,77]
wherethefirstelementisthetopofthestack.
S.push(75)S.pop()S.pop()S.push(31)S.pop()S.push(8)
WhatdoesSlooklikeoncetheoperationsaboveareexecutedinorder?A. S=[12,31,77,75,31,8]B. S=[8,31,75,0,8,18]C. S=[0,8,18,12,31,8]D. S=[8,8,18,12,31,77]
Question 2ATuringmachineisrunwithasetofinstructionsdesignedtosolveaproblem.Themachineisrunmultipletimesusingrandomlyselectedinputs.Onsomeinputsthemachinehaltsandacceptstheinputandonallotherinputsithaltsandrejectstheinput.Whenthemachinehalts,thesolutionproducedbytheinputcanbequicklyverified.Whichoneofthefollowingstatementsisdefinitelytrue?A. TheproblemisdecidableandinNP.B. TheproblemisundecidableandinNP.C. TheproblemisdecidableandnotinNP.D. TheproblemisundecidableandnotinNP.
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
c
a
b
bb
( )( )( log )( )
loglogloglog
=
<=
ififif bb a c>
Page 4
2019ALGORITHMICSEXAM 4
SECTION A – continued
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Use the following information to answer Questions 3 and 4.Acountryhassixstates.Eachstatehasitsownmajorcity.Belowisatableofthemajorcities(A–F)andtheirdistancesapartinkilometres(km).
City
F
E 720
D 550 1060
C 860 400 250
B 940 1800 1380 750
A 1600 960 1160 640 1160
A B C D E F
Question 3Veronicahasafreeticketthatallowshertotravelatmost2000kmstartingfromanycity.Shewantstovisitasmanycitiesaspossiblesoshechoosestovisitthecitiesthatarenearesteachotherfirst.Shedoesnotneedtoreturntothecitywhereshestartsherjourney.ThethreemostprobablecitiesthatVeronicawillvisit,inorder,areA. A → B →CB. B →C→DC. F→C→ED. F→C→D
Question 4Elianahasfreeticketsthatallowhertotravelamaximumof10000km.However,shewantstovisitonlycitiesA,B,CandD,andshewantstosavetheremainingticketstomaximiseherfuturetravels.Shedoesnotneedtoreturntothecitywhereshestartsherjourney.WhatwillbeEliana’sbestroute?A. A → B →C→DB. A →D→C→ BC. C→D→ B → AD. D→ A →C→ B
Question 5Stanisstoringaseriesoftimingobservationsforafunctionheiswritingsohecancalculatetheaverageamountoftimetakenforanobservation.Forthisgivenproblem,whichabstractdatatype(ADT)wouldbethemostsuitable?A. queueB. graphC. stackD. array
Page 5
5 2019ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 6SahilistestinghisfriendJulia’sknowledgeofrecurrencerelations.Hewritesthefollowingrecurrencerelationforanalgorithm.
( ) 2 (1)2nT n T O = +
Whichalgorithm(s)hasSahilwrittentherecurrencerelationfor?A. quicksortonlyB. mergesortonlyC. bothquicksortandmergesortD. neitherquicksortnormergesort
Question 7WhichoneofthefollowinggraphsbestrepresentsBig-Θwhenconsideringextremelylargevaluesofn?
c2 . g (n)
f (n)c1 . g (n)
c . g (n)
f (n)
f (n)
c . g (n)
f (n)
c2 . g (n)
c1 . g (n)
A.
C.
B.
D.
Question 8Aquicksortalgorithmwithanunknownimplementationwillbeusedtosortalargearrayofelementswherethepivotischosenasthefirstelementinthearray.Whatpropertymusttheinputtothisarrayhaveinordertominimisethechanceofreachingtheworstcaseruntimecomplexity?A. Theinputmustberandom.B. Theinputmustbepre-sorted.C. Theinputmustbeinascendingorder.D. Theinputmustbeindescendingorder.
Question 9ThemaingoalofDavidHilbert’s1927programwastoA. provethatasystemwithacomputablesetofaxiomscouldneverbecomplete.B. removeallparadoxesandinconsistenciesfromthefoundationsofmathematics.C. provethatitisnotpossibletoformaliseallmathematicalstatementsaxiomatically.D. constructastatementthatcanbederivedfromformalaxiomaticrulesandcanbeshowntobetrue.
Page 6
2019ALGORITHMICSEXAM 6
SECTION A – continued
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 10WhichoneofthefollowingdescriptionsoftheFloyd-WarshallalgorithmfortransitiveclosureofagraphhavingVverticesandEedgesiscorrect?A. ThetimecomplexityofthealgorithmisΘ(E3).B. ThetimecomplexityofthealgorithmisΘ(V 2log V).C. Thealgorithmfindsthetransitiveclosureofagraphwhetheritisdirectedorundirected.D. Thealgorithmfindsthetransitiveclosureofadirectedgraphbyusingtheweightededgesaspartof
constructingtheadjacencymatrix.
Question 11WhichoneofthefollowingdescriptionsofP,NPandNP-completeproblemsisincorrect?A. ItisageneralbeliefthatNP-completeproblemsareconsideredtobehardertosolvethanPproblems.B. Normally,heuristicsareappliedtosolveNP-completeproblems.Thesolutionobtainedmaybeexact.C. IfanNP-completeproblemcanbesolvedinPtime,allNP-completeproblemscanalsobesolvedin
Ptime.Inthatcase,P=NP.D. IfanNP-completeproblemcanbesolvedinPtime,allNP-completeproblemscanalsobesolvedin
Ptime.Inthatcase,itisstillnotknownwhetherP=NP.
Question 12Considerthefollowingalgorithm.
Algorithm myFunction(a)Begin If (a < 1) Then Return 2 Else b a - 3
Return a + myFunction(b) EndIfEnd
Whatisthevalueattheendofthealgorithmifitisrunwiththeinputa=4?A. 5B. 6C. 7D. 2
Page 7
7 2019ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 13ThestringABCFEDisobtainedasabreadth-firstsearchthroughadirectedgraph,beginningatA.Whichoneofthefollowingtreescouldrepresentthegraphbeingsearched?
A B C
D E F
A B C
D E F
A B C
D E F
F
A B C
D E
A.
B.
C.
D.
Question 14
(XorY)and(not(X)orZ)and(not(Z)orY)
Underwhichcircumstancesistheconditionalexpressionabovetrue?A. whenXandYaretrue,orXisfalseandatleastoneofYandZistrueB. whenallofX,YandZaretrue,orXisfalseandYistrueC. whenexactlytwoofX,YandZaretrueD. whenallofX,YandZarefalse
Page 8
2019ALGORITHMICSEXAM 8
SECTION A – continued
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 15Aprogramwithanestedloopiteratesntimesfortheouterloopandn –1timesfortheinnerloop.WhatistheBig-Ocomplexityofthisprogram?A. O(n –1)B. O(n2)C. O(1)D. O(n)
Question 16Sebastianisworkingwithagraphthatcontainsedgeswithnegativeweights.Heneedstoimplementanalgorithmtocalculatetheshortestpathfromaparticularnode.WhichgraphalgorithmshouldSebastianimplementandforwhatreason?A. theBellman-FordalgorithmasDijkstra’salgorithmdoesnotalwaysprovideacorrectsolutionB. Dijkstra’salgorithmastheBellman-FordalgorithmdoesnotalwaysprovideacorrectsolutionC. theBellman-FordalgorithmduetothenegativeweightsD. Dijkstra’salgorithmduetothenegativeweights
Question 17Whichofthefollowingproperties,whereintensificationnarrowsthesearchtoalocalregionanddiversificationconsidersotherregionsofthesearchspace,ismorelikelytocauseconvergencetowardsglobaloptimalitywhenassessingmeta-heuristicalgorithms?A. intensificationbyitselfB. diversificationbyitselfC. bothintensificationanddiversificationD. neitherintensificationnordiversification
Question 18WhichoneofthefollowingstatementsaboutBig-O,Big-ΩandBig-Θnotationiscorrect?A. AnalgorithmhavingabestcasecomplexityofΩ(nlogn)mustalsohaveanaveragecasecomplexityof
Θ(nlogn).B. AnalgorithmhavingaworstcasecomplexityofΘ(nlogn)willhaveaworstcasecomplexityof
O(nlogn).C. AnalgorithmhavingaworstcasecomplexityofO(n2)mustalsohaveaworstcasecomplexityofΘ(n2).D. AnalgorithmhavingabestcasecomplexityofΩ(n)willalsohaveaworstcasecomplexityofO(n).
Page 9
9 2019ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
Question 19ThefollowingpseudocodeforFloyd’sall-pairshortestpathalgorithmisincomplete.
Let D be a |V| × |V| array of minimum distances initialised to ∞
For each edge (u,v) Do D[u][v] w(u,v) // the edge weight (u,v)
For each vertex v Do D[v][v] 0
EndFor For k from 1 to |V| Do For i from 1 to |V| Do For j from 1 to |V| Do // this section is incomplete
EndFor EndFor EndForEndFor
Whichoneofthefollowingpseudocodeextractswillcompletethealgorithm?
A. If D[i][j] > D[i][k] + D[j][k] Then D[i][j] D[i][k] + D[k][j]
EndIf
B. If D[i][j] < D[i][k] + D[j][k] Then D[i][j] D[i][k] + D[k][j]
EndIf
C. If D[i][j] < D[i][k] + D[k][j] Then D[i][j] D[i][k] + D[k][j]
EndIf
D. If D[i][j] > D[i][k] + D[k][j] Then D[i][j] D[i][k] + D[k][j]
EndIf
Page 10
2019ALGORITHMICSEXAM 10
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
END OF SECTION A
Question 20Whichoneofthefollowingdescriptionsofdynamicprogramminganddivideandconqueriscorrect?A. Dynamicprogrammingaimstosolvethesub-problemsonce,whethertheyareoverlappingornot,
whereasdivideandconquerdoesnotcareabouthowmanytimesitneedstosolveasub-problem.
B. Divideandconqueraimstosolvethesub-problemsonce,whethertheyareoverlappingornot,whereasdynamicprogrammingdoesnotcareabouthowmanytimesitneedstosolveasub-problem.
C. Dynamicprogrammingaimstofindanoptimalsolutionforaproblembysplittingitinto non-overlappingsub-problems,findingtheoptimalsolutionsforthesub-problems,andcombiningtheoptimalsolutionsforthesub-problemstoformtheoptimalsolutionfortheoriginalproblem.
D. Divideandconqueraimstofindanoptimalsolutionforaproblembysplittingitintooverlappingsub-problems,findingtheoptimalsolutionsforthesub-problemswiththeintentionofsolvingtheoverlappingsub-problemsonlyonce,andcombiningtheoptimalsolutionsforthesub-problemstoformtheoptimalsolutionfortheoriginalproblem.
Page 11
11 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
Question 1 (3marks)Explain,usinganexample,theroleofthetapeinaTuringmachine.
Question 2 (2marks)Amergesortalgorithmrunsonaninitialarrayinput,x,withabestcaserunningtime.Itreturnsthesortedarray[0,2,4,6,8,10,12,14].
Whatistheinitialarrayinputx?Explainyouranswer.
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
c
a
b
bb
( )( )( log )( )
loglogloglog
=
<=
ififif bb a c>
Page 12
2019ALGORITHMICSEXAM 12
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 3–continued
Question 3 (8marks)Aspecialcalculatorisdesignedtoacceptaninputstreamofsymbols.Thesymbolscanbeeitheranumberoranarithmeticoperatorsuchas+,−,×and÷.Thecalculatorworksinthefollowingway:• Wheneveritencountersanumber,thecalculatorwillappendthenumbertoaspeciallocation
designatedforstoringthenumbersandpreservetheirorderfromtheinput.• Wheneveritencountersanarithmeticoperator,thecalculatorwilldothefollowing:
– fetchthelasttwonumbersstoredinthespeciallocationwithxbeingthesecond-lastnumberandy beingthelastnumber
– performthearithmeticoperationwithxbeingthefirstoperandandybeingthesecondoperand
– puttheresultbackintothespeciallocationasthelastentryForexample,ifthenumbersinthespeciallocationare8,1,6,2anditencountersa÷,thenumbersinthespeciallocationaftertheoperationwillbe8,1,3because6÷2=3and3isputbackintothespeciallocationasthelastentry.
• Whentheinputstreamisusedup,thecalculatorwillfetchthelastnumberinthespeciallocationandthendisplayitasthefinalresultofthecalculation.
• Wheneveritcannotperformitsoperations(forexample,itcannotfetchtwonumbersfromthespeciallocationtoperformthearithmetic),thecalculatorwilldisplay‘Error’.
Anexampleofaninputstreammaybe
22 3 − 100 20 × +
Forthisexampleofaninputstream,thecalculatorwilldisplay2019asthefinalresult.
Page 13
13 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
a.
8 3 + 18 2 ÷ ×
Whatwillbethefinaldisplayiftheinputstreamisasshownabove?Explainyouranswer. 3marks
b. i. Selectthemostappropriateabstractdatatype(ADT)tomodelthenumbersstoredinthespeciallocationofthecalculator.Explainyouranswer. 2marks
ii. WritetheADTspecificationfortheADTselectedinpart b.i. 3marks
Page 14
2019ALGORITHMICSEXAM 14
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continued
Question 4 (4marks)Adaiscurrentlystudyingarraydatastructures.Shecomesupwiththefollowingwayofcomparingtwonumericarraysofthesamesize.Anumericarrayisonewhereallofitsentriesarenumbers.LetAandBbetwonumericarraysofsizen.ThearrayAissaidtobegreaterthanorequaltothearrayB,denotedasA≥ B,ifforatleasthalfofthevaluesofi,theconditionA[i]≥B[i]holdswherei=1,…,n.AdawantstowriteanalgorithmtodeterminewhetherAisgreaterthanorequaltoB.Shehasalreadyimplementedthefollowingtwoalgorithms:1. analgorithmcalledsortAscendingthatwillsortanumericarrayofsizeninascending
orderwithaworstcasetimecomplexityofO(n2)2. analgorithmcalledmedianthatreturnsthemedianvalueofanumericarraywithatime
complexityofO(1)
AdawritesthefollowingpseudocodetodeterminewhetheranumericarrayAisgreaterthanorequaltoB,bothofsizen.
Algorithm isGreaterOrEqual(A, B, n)Begin A sortAscending(A, n)
B sortAscending(B, n)
mA median(A, n)
mB median(B, n)
If mA >= mB Then Return true Else Return false EndIfEnd
a. WhatistheworstcasetimecomplexityofisGreaterOrEqual?Explainyouranswer. 2marks
b. IsAda’spseudocodeforisGreaterOrEqualcorrect?Explainyouranswerusinganexample. 2marks
Page 15
15 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
Question 5 (4marks)WeihasjustfinishedreadingabouttheHaltingProblemandisstillconfusedaboutwhattheHaltingProblemis.
WritepseudocodetodemonstratetheHaltingProblemtoWei.Includerelevantannotations.
Page 16
2019ALGORITHMICSEXAM 16
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 6–continued
Question 6 (7marks)AmetropolitantraincompanyhasaskedMaiatoassistwithschedulingtrainstravellingalongatrainnetwork.Eachstationalongthenetworkhastwoplatformsandinterconnectingtracks.Theexpectedwaittimeateachplatformandthetimetakentotravelalongthattrackdependonthenumberofstaffallocatedtoassistwithboardingandsignalling.Attimes,platformsortracksmaybeclosedforrepairs.Theproposednetworkismodelledbelow.
train
platform isclosed due totrack repairs
A B
A B
A B
A
A
B
B
A B
Keyfunctioning trackstracks closed for repairs
stationA
Page 17
17 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
a. Oneapproachtohelpwithschedulingistouseabrute-forcealgorithmtoreducecongestionforeachtraintravellingthroughthenetwork.
Explainwhetherornotthisisfeasible.Includethetimecomplexityinyourexplanation. 4marks
b. Maiasuggeststhatadynamicprogrammingapproachshouldbeusedforschedulingasthetrainnetworkislikelytoexpand.
Whatpropertiesofthisproblemmakeitsuitableforadynamicprogrammingapproach? 3marks
Page 18
2019ALGORITHMICSEXAM 18
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 7–continued
Question 7 (10marks)Erichasbeenemployedbyachemistrylaboratorytotestthepurityofamaterialitmanufacturescalledstrongsheet.Strongsheetisamaterialmadeofpurecarbon,althoughthelaboratoryisstillperfectingitsmanufacturingprocessandtherearesomeimpuritiespresent.Thefollowingimageshavebeenproducedusinganelectronmicroscope.Figure1isanidealsampleofastrongsheetstructure,whileFigure2hasvariousimpuritiescreatingunwantedlinksinthelattice.
Figure 1 Figure 2
Ideal structure Current structure
a. Explainhowgraphcolouringcanbeusedtotestthepurityofthestrongsheetsample. 2marks
b. Asthelaboratoryincreasesthesizeofitsstrongsheets,willitstillbeabletousegraphcolouringtotestforpurity?Explainyouranswer. 3marks
Page 19
19 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
c. Writeagreedyalgorithmthatcanbeusedtocomputeovertheselectedsamples,Figure1andFigure2,shownonpage18. 5marks
Question 8 (4marks)ExplaintherelationshipbetweenCobham’sthesisandtheChurch-Turingthesis.Aspartofyourexplanation,includeadefinitionofboththeses.
Page 20
2019ALGORITHMICSEXAM 20
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continued
Question 9 (4marks)DescribehowDNAcomputingworksandexplainhowitcanbeusedtoovercomethecurrentlimitsofcomputation.
Question 10 (5marks)Outlinehowinductioncanbeusedtoshowthatatreewithnverticeshasn –1edges.Youmaydrawandannotateadiagramaspartofyouranswer.
Page 21
21 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
Question 11 (2marks)UsingPrim’salgorithm,findtheminimalspanningtreefortheweightedgraphbelow,startingfromA.Showtheorderoftheedgesaddedtothetree.
A B C
D E
F G H
A B C
D E
F G H
Order
11
4
6
2 6
7
5
5
10
47
10
3
Page 22
2019 ALGORITHMICS EXAM 22
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 12 – continued
Question 12 (8 marks)A cellular automaton is a system in which each row is generated based on the row before it, in particular the cell above, the cell above to the left and the cell above to the right. The rules can vary, but for this question the rule is given as the following.
Rule
1 1 1 1 1 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 0 0 00 1 1 1 0 0 0 0
Assume the edges are considered 0, that is, the cells on the edge do not consider the cells on the other edge. For example, given the rule above with a row containing a single 1, the next few rows will be
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1
a. Given the input row 0 1 1 1 0 1 0 1 1 0 , determine the next row. 1 mark
Page 23
23 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
b. Drawadecisiontreetoimplementthiscellularautomatarule. 3marks
c. Writepseudocodethattakesaninputarraycontainingacombinationofeight0sand1s,andgeneratesn,thenumberofrows.Row0shouldcontaintheinputrow. 4marks
Page 24
2019ALGORITHMICSEXAM 24
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continued
Question 13 (4marks) Donnahasanumberofforms,numberedfrom1to5,thatneedtobedeliveredtoclassroomsataschool.Shehasmadealistofclassroomnamesand,foreachclassroom,shehascreatedatableofhowmanyofeachformneedtobedelivered.Forexample
1 2 3 4 5
1A 0 1 3 2 0
1B 1 4 5 2 1
Donnawouldliketogettheseformsdeliveredinthequickestwaypossible.Atthemomentsheintendstoproceedinclassroomorder.
AdviseDonnaonanalternativewayofdeliveringtheformsthatwillbemoreefficient.
FormsClassrooms
Page 25
25 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 14–continuedTURN OVER
Question 14 (9marks)Joefindsitverytime-consumingtoperformthemultiplicationoftwotwo-dimensionalnumericarraysofsizen ×n.HeasksAlex,BettyandChloetohelphimwriteaprogramtoperformthemultiplication.Alexfirstattemptstoimplementthemultiplicationaccordingtothefollowingpseudocode.
Algorithm multiply(A, B, n)
Begin
For i = 1 to n Do
For j = 1 to n Do
Product[i][j] 0
For k = 1 to n Do
Product[i][j] Product[i][j] + A[i][k] × B[k][j]
EndFor
EndFor
EndFor
Return Product
End
AssumethemultiplicationandadditionoftwonumberscanbeperformedinO(1)time.
a. WhatisthetimecomplexityofAlex’spseudocode?Justifyyouranswer. 2marks
Page 26
2019ALGORITHMICSEXAM 26
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – Question 14–continued
ThepseudocodetoaddAandB,twon×nnumericarrays,isgivenbelow.
Algorithm add(A, B, n)Begin For i = 1 to n Do For j = 1 to n Do Sum[i][j] A[i][j] + B[i][j]
EndFor EndFor Return SumEnd
Bettycomesupwiththefollowingrecursivemethodofmultiplyingthearrayswhen n is 1 or n can be divided by 2:• Step1–Whennis1,thatisA=A[1][1]andB=B[1][1],justmultiplythetwonumberstogethertoobtain
theproduct,thatisC[1][1]=A[1][1]×B[1][1],andreturnC.
• Step2–Otherwise,dothefollowing:
I. Spliteachtwo-dimensionalarrayintofoursmallertwo-dimensionalarraysofsize(n/2)×(n/2). Then,thetwo-dimensionalarraysAandBwillbedenotedas
A BA A
A A
B B
B B=
=
, ,
, ,
, ,
, ,
1 1 1 2
2 1 2 2
1 1 1 2
2 1 2 2and
whereA1,1,A1,2,A2,1andA2,2arethetwo-dimensionalarraysofsize(n/2)×(n/2)splitfromA, andB1,1,B1,2,B2,1andB2,2arethosesplitfromB.
II. Performthefollowingmultiplicationsandadditions.
C A B A B
C A B A B
C A
1 1 1 1 1 1 1 2 2 1
1 2 1 1 1 2 1 2 2 2
2 1 2 1
, , , , ,
, , , , ,
, ,
= × + ×
= × + ×
= × BB A B
C A B A B1 1 2 2 2 1
2 2 2 1 1 2 2 2 2 2
, , ,
, , , , ,
+ ×
= × + ×
III. Formtheresultanttwo-dimensionalarrayCusingthefollowingformatandreturnit.
CC1,1
C2,1
C1,2
C2,2=
Page 27
27 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continuedTURN OVER
b. AssumeboththemultiplicationandadditionoftwonumberscanbeperformedinO(1)time.
T nT n n n n
n( ) =
+ >
=
82
1
1 1
2 if and is even
if
ExplainwhythetimecomplexityofBetty’salgorithmcanbeobtainedusingtherecurrencerelationabove. 3marks
c. WhatisthetimecomplexityofBetty’srecursivealgorithm?Explainyouranswer. 2marks
d. Chloesaysthatsheknowsanotherrecursivemethodforthemultiplicationthatgivesthefollowingrecurrencerelationship.
T n T n n n
n( ) =
+
>
=
72
182
1
1 1
2
if
if
Isthisnewmethodfasterthantheprevioustwo?Justifyyouranswer. 2marks
Page 28
2019ALGORITHMICSEXAM 28
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
SECTION B – continued
Question 15 (2marks)ThefollowingPageRank(PR)hasbeencalculatedusingthePageRankalgorithmforfourwebpages.AllPRvaluesaregreaterthanzero.
Page APR = w
Page BPR = x
Page CPR = y
Page DPR = z
ExplainwhyPageDhasaPRvaluegreaterthanzerodespitehavingnoincominglinks.Usemathematicalcalculationsaspartofyourexplanation.
Page 29
29 2019ALGORITHMICSEXAM
do
no
t w
rit
e i
n t
his
ar
ea
do
no
t w
rit
e i
n t
his
ar
ea
END OF QUESTION AND ANSWER BOOK
Question 16 (4marks)StellaandCameronareplayingaturn-basedgamethatallowseachplayertocollectpointsbasedonaheuristicvalueofspecialcardsdealtface-uponthetable.Ateachturn,aplayerchoosesonecardfromachoiceoftwocards.Thegoalofthegameisforaplayertoscorethehighestnumberofpoints.BelowisanincompleteminimaxgametreeofStellaandCameron’sgame,wherethecirclesrepresentthemovesofStella,themaximisingplayer,andthesquaresrepresentthemovesofCameron,theminimisingplayer.
ExplainhowtheminimaxalgorithmcanbeusedbyStellatogiveherthebestchanceofwinningthegame.Completethegametreeaspartofyourexplanation.
4 5 9 2 5 6 8 1 3 7 7 6 5 3 8 5