ALGORITHMICS (HESS)Written examination
Monday 31 October 2016 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 17 17 80
Total 100
• Studentsarepermittedtobringintotheexaminationroom:pens,pencils,highlighters,erasers,sharpeners,rulersandonescientificcalculator.
• StudentsareNOTpermittedtobringintotheexaminationroom:blanksheetsofpaperand/orcorrectionfluid/tape.
Materials supplied• Questionandanswerbookof30pages.• 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.
©VICTORIANCURRICULUMANDASSESSMENTAUTHORITY2016
SUPERVISOR TO ATTACH PROCESSING LABEL HEREVictorian Certificate of Education 2016
STUDENT NUMBER
Letter
2016ALGORITHMICSEXAM 2
SECTION A – continued
Question 1Considerthefollowingpseudocode,whereaandnarepositiveintegers.
b = -1c = ai = 0while(i is less than or equal to n) c = c * b i = i + 1endwhile
Whichoneofthefollowingstatementscorrectlydescribesthevalueofcafterthealgorithmisexecuted?A. cisundefinedB. cisequalto–1C. cisequalto–aifnisoddD. cisequalto–aifniseven
Question 2WhichoneofthefollowingstatementsaboutFloyd-Warshall’salgorithmrunningonagraphwithVnodesandEedgesiscorrect?A. TherecursiveversionfindsthetransitiveclosureofagraphinO(3V)time.B. Theiterative(dynamicprogramming)versionfindstheshortestpathbetweenallpairsofnodesin
O(V 3)time.C. Theiterative(dynamicprogramming)versionfindstheshortestpathbetweenallpairsofnodesin
O(3E)time.D. Theiterative(dynamicprogramming)versionalwaysfindsaminimalspanningtreerootedatevery
nodeinO(V 3)time.
Question 3Considerthefollowingthreeparametersofafunction:• row,whichcantakethevalues1or2• column,whichcantakethevalues‘a’or‘b’or‘c’• sound,whichcantakethevaluesTrueorFalse
Whichoneofthefollowingstatementsistrue?A. Pair-wisetestingofthefunctionrequiressixtestcases.B. Pair-wisetestingofthefunctionrequires12testcases.C. Exhaustivetestingofthefunctionrequiressixtestcases.D. Exhaustiveblack-boxtestingofthefunctionrequires7!testcases.
SECTION A – Multiple-choice questions
Instructions for Section AAnswerallquestionsinpencilontheanswersheetprovidedformultiple-choicequestions.Choosetheresponsethatiscorrectorthatbest answersthequestion.Acorrectanswerscores1;anincorrectanswerscores0.Markswillnotbedeductedforincorrectanswers.Nomarkswillbegivenifmorethanoneansweriscompletedforanyquestion.
3 2016ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Question 4Considerthefollowingfunctionf(x,y)thattakestwointegersasinput.
f(x,y)begin if (x < 0 or y < 0) if (x > y) a = y else a = x endif else if (x > y) a = x else a = y endif endif
return aend
Whichoneofthefollowingsetsoftestcasescoversallpathsofthefunction?A. {(x=–3,y=4), (x=–2,y=6), (x=3,y=6), (x=3,y=1)}B. {(x=–3,y=–4), (x=–2,y=6), (x=3,y=6), (x=3,y=1)}C. {(x=–3,y=–4), (x=–2,y=6), (x=3,y=6), (x=3,y=3)}D. {(x=–3,y=–4), (x=–2,y=6), (x=3,y=–6), (x=3,y=1)}
Question 5Whenconsideringdifferenttypesofalgorithms,whichoneofthefollowingstatementsistrue?A. Divideandconqueralgorithmsarealwaysfasterthangreedyalgorithmsforthesameproblem.B. Greedyalgorithmsarealwaysfasterthandivideandconqueralgorithmsforthesameproblem.C. Greedyalgorithmsgivegoodapproximateanswerstoproblems,butneverthebestpossibleanswer.D. Brute-forcealgorithmscanneverbefasterthanawell-designedgreedyalgorithmforthesameproblem.
Question 6Alargenumberofpeoplewillbecompletinganonlinesurvey.Eachsurveyresponsewillbestoredintheorderitissubmitted.Whichabstractdatatype(ADT)wouldbethemostappropriateforstoringthesurveyresponses?A. graphB. queueC. stackD. dictionary
2016ALGORITHMICSEXAM 4
SECTION A – continued
Use the following information to answer Questions 7 and 8.
A
B
E
GD
F
C
H
Question 7Adepth-firstsearchtraversalofthegraphabovewillvisitthenodesinwhichoneofthefollowingorders?(Alphabeticalorderisusedwhenthereismorethanoneoption.)A. ABDGEFCHB. ABDEFCHGC. ABEGFCHDD. ABDFCHEG
Question 8Abreadth-firstsearchtraversalofthegraphabovewillvisitthenodesinwhichoneofthefollowingorders?(Alphabeticalorderisusedwhenthereismorethanoneoption.)A. ABEGFCHDB. ABDGFECHC. ABDGEFCHD. AGBDEFCH
Question 9Aconnected,undirectedgraphwithdistinctedgeweightshasmaximumedgeweightemaxandminimumedgeweightemin.Whichoneofthefollowingstatementsisfalse?A. emaxisnotinanyminimalspanningtree.B. Everyminimalspanningtreeofthegraphmustcontainemin.C. Prim’salgorithmwillgenerateauniqueminimalspanningtree.D. Ifemaxisinaminimalspanningtree,itsremovalwilldisconnectthegraph.
5 2016ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Question 10Dijkstra’ssingle-sourceshortestpathalgorithminanundirectedgraphreportsdistancesfromthesourcetoeachnode.ThesedistancesA. aretheshortestpossibledistancestoeverydestinationnode.B. arenevertheshortestpossibledistanceswhennegativeedgeweightsarepresent.C. maybetheshortestpossibledistanceswhennegativeedgeweightsarepresent.D. maynotalwaysbetheshortestpossibledistanceswhenalledgeweightsarepositive.
Question 11Considerthefollowingfouralgorithms,operatingonagraphwithV nodesandE edges:1. Floyd-Warshall’salgorithmfortransitiveclosure2. Bellman-Ford’salgorithmforthesingle-sourceshortestpathproblem3. depth-firsttraversalalgorithm4. Dijkstra’salgorithmforthesingle-sourceshortestpathproblem
Thetimecomplexitiesofthesealgorithms,inorder,areA. O(V 3),O(VE),O(V 2),O(V+E)B. O(V+E),O(V 3),O(VE),O(V 2)C. O(V 3),O(VE),O(V+E),O(V 2)D. O(VE),O(V+E),O(V 3),O(V 2)
2016ALGORITHMICSEXAM 6
SECTION A – continued
Question 12
Algorithm AInput: two nodes X, YOutput: “yes” if successful, “no” otherwise
Let L = an empty listAppend X to L
while(L is not empty) Let Z = first node in L if(Z = Y)then return “yes” else Remove Z from L for every neighbour N connected to Z if(N.visited = False and N is not in L) Append N to the end of L endif endfor Z.visited = True endifendwhile
return “no”
ThealgorithmaboveusesA. breadth-firstsearch.B. depth-firstsearch.C. mergesort.D. minimax.
Question 13AfterkiterationsofBellman-Ford’salgorithminagraphwithnnodes(1<k<n–1),whichstatementistrueabouttheshortestpathsfromthesourcenodetoeveryothernode?A. Theshortestpathswithatmostkedgeshavebeenfound.B. Theshortestpathswithatmostk–1edgeshavebeenfound.C. Theshortestpathswithatmostk+1edgeshavebeenfound.D. Theshortestpathsforanynumberofedgescanchangeasthealgorithmhasnotcompleted.
Question 14ThePageRankalgorithmusestwoattributestocalculatethepopularityofawebpage.Whichoneofthefollowingstatementsbestdescribestheseattributesforcalculatingawebpage’sPageRank?A. thenumberofoutboundandinboundlinksofawebpageB. theprobabilityofarandomdirectlandingonawebpageandthesizeofthewebpageC. thenumberofoutboundlinksofawebpageandtheprobabilityofarandomdirectlandingonthe
webpageD. thenumberofinboundlinksofawebpageandtheprobabilityofarandomdirectlandingonthe
webpage
7 2016ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Use the following information to answer Questions 15 and 16.BlackboxInc.istryingtosellnewtimetablingsoftwaretoaschool.Thefollowingdatashowsrunningtimes(inmicroseconds)forhowthenewtimetablingsoftware’salgorithmcompareswithastandardbaseline,wheren isameasureofthesizeofthetimetablingproblem.
n Baseline New algorithm
1 5 3
10 105 53
100 1998 103
1000 29 902 152
10 000 398636 202
Question 15WhichBig-Oexpressionmostcloselydescribestherunningtimeofthebaseline?A. O(n)B. O(n2)C. O(logn)D. O(nlogn)
Question 16WhichBig-Oexpressionmostcloselydescribestherunningtimeofthenewalgorithm?A. O(n)B. O(n2)C. O(logn)D. O(nlogn)
Question 17InthecontextofAlgorithmics,adecisionproblemisA. aproblemwithonlytwopossiblesolutions.B. aproblemwithmorethantwopossiblesolutions.C. aproblemforwhichallknownalgorithmsdonotterminate.D. undecidableaccordingtotheChurch-TuringthesisbecauseitdoesnotterminateonaTuringmachine.
2016ALGORITHMICSEXAM 8
SECTION A – continued
Use the following information to answer Questions 18 and 19.ATuringmachineisconfiguredwiththeinstructionsrepresentedinthestatediagrambelow.
begin
blank/blank:R blank/blank:R
blank/1:L
1/1:L
1/0:R
0/1:R
0/0:L
0/0:L
1/1:L
haltq0
q1q2
Eachedgeislabelledi / j : k,where:• iistheinput• jistheoutput• kisthedirectiontheheadmoves(L=left,R=right)aftertheoutput.
Themachinebeginsinstateq0.Themachineisgiventhefollowingtape.Forthismachine,thetaperemainsstationarywhiletheheadmoves.
0 1 0 0 1 0 1
9 2016ALGORITHMICSEXAM
SECTION A – continuedTURN OVER
Question 18TheTuringmachineisrunwiththetape.WhentheTuringmachinehalts,theappearanceofthetapeandthepositionoftheheadareasfollows.Thearrowshowstheendingpointofthehead.
1 1 0 0 1 0 1
WhichoneofthefollowingbestrepresentsthepositionoftheheaddirectlybeforetheTuringmachinestarted?
0 1 0 0 1 0 1
0 1 0 0 1 0 1
0 1 0 0 1 0 1
0 1 0 0 1 0 1
A.
B.
C.
D.
Question 19Thearrowbelowshowsthestartingpointoftheheadbeforethemachineisrunagain.
0 1 0 0 1 0 1
WhentheTuringmachinehalts,thenumberofstepsthattheheadwillhavemovedisA. 6B. 7C. 9D. 10
2016ALGORITHMICSEXAM 10
END OF SECTION A
Question 20AstudentbeginstowritethefollowingsignatureforaqueueADT.
name queueimport element, booleanoperations empty : → queue isEmpty : queue → boolean
peek : queue → element
enqueue : queue × element → queue
dequeue :
Whichoneofthefollowingisthecorrectrepresentationofthedequeueoperation?A. dequeue : queue → queue
B. dequeue : queue → boolean
C. dequeue : element → queue
D. dequeue : queue → element
11 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 1 (3marks)Explainhowrandomisedheuristicscanhelpovercomethesoftlimitsofcomputation.Useanexampleaspartofyourexplanation.
Question 2 (3marks)Alaboratoryisworkingona3D-printedstructurethatusesanewexperimentalmaterial.Thematerialismadeupofsixseparatecomponentsandneedstobestructuredinsuchawaythatnocomponentconnectstoanothercomponentofthesametype.Ifcomponentsofthesametypedoconnect,thestructurewillcollapse.Theconnectionsbetweenthecomponentscanbetreatedasagraph.
Describeanapproachthatcouldbeusedinreasonabletimetoensurethatstructuresofanysizewouldnotcollapse.
SECTION B
Instructions for Section BAnswerallquestionsinthespacesprovided.
2016ALGORITHMICSEXAM 12
SECTION B – continued
Question 3 (3marks)Acompanymakessyntheticdiamondstoselltocustomerswhousetheminhigh-poweredlasers.Thecompanyhasreceivedcomplaintsfromitscustomersaboutsomeofthediamondsbeingfaulty,makingthelasersunsafetouse.Oninvestigating,atechniciannoticesthatthefaultydiamondsweighafewmicrogramslessthanthediamondsthatarenotfaultyandthateachbatchofdiamondsisproducingexactlyonefaultydiamond.Asthediamondsareproducedinverylargebatches,itwouldnotbefeasibletosimplyweigheachdiamonduntilthefaultyoneisfound.Themanagerwouldliketoputinplaceamethodtofindfaultydiamonds.
Stateanappropriatealgorithmdesignpatternthatthemanagercouldusetosuccessfullyfindfaultydiamondsandexplainhowthatalgorithmwillsolvetheproblemefficiently.
13 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 4 (2marks)Whendataistransferredacrosscomputernetworks,itisfirstbrokenupintopackets.Computernetworktrafficisnormallyprocessedintheorderthatpacketsarriveateachdevicealongthepathbetweencommunicatingdevices.Packetsmaybepiecesofemail,webcontent,voiceorvideo.Whilesometraffic,suchasemailorwebcontent,canwithstanddelaysindelivery,others,suchasvoiceandvideo,cannothavedelays;thesepacketscannotwaitateachdeviceforothertraffictobeprocessedaheadofthem.
Describeastandardabstractdatatype(ADT)thatcouldbeusedtomanagethepacketsarrivingatacomputer.
Question 5 (2marks)Anundirectedgraph,G,ispossiblydisconnected.
Howcanadepth-firstsearchalgorithmbemodifiedtocheckfordisconnectedness?
2016ALGORITHMICSEXAM 14
SECTION B – Question 6–continued
Question 6 (6marks)Thefollowinggraphrepresentslinksbetweenwebpages.
A D
B
C
ThePageRankofPageAisgivenby
PRPRL
PRL
PRL
AdN
dBB
CC
DD
( ) = −( )+
( )( )
+( )( )
+( )( )
1
wherePR(x)isthePageRankofPagex,NisthenumberofpagesinthisnetworkandL(x)isthenumberofoutgoinglinksfromPagex.
a. ExplainthepurposeofdinthePageRank. 2marks
b. Whatdoes1−( )dN
representinthePageRank? 1mark
c. Whatdoes dBB
CC
DD
PRL
PRL
PRL
( )( )
( )( )
( )( )
+ +
representinthePageRank? 1mark
15 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
d. Anewpage,E,isaddedtothegraphasanode,shownbelow.
A
B
C
D E
ExplainhowthePageRankwouldincludenodeEiftherearenooutboundlinksfromPageE. 2marks
2016ALGORITHMICSEXAM 16
SECTION B – continued
Question 7 (3marks)AstudentrunsBellman-Ford’ssingle-sourceshortestpathalgorithmonthefollowingdirectedgraphusingnodeAasthesource.Afternineiterations,shenotesthedistancefromAtoeachoftheothernodes.ShethenrunsatenthiterationofthealgorithmandnotesthedistancefromAtoeachoftheothernodes.
A
B
D
C
G
I
J
F H
E–2 3
52
2 7
–3
10
1
5 –4
5
–2 –3
a. WhichnodeswillshowachangeindistancefromsourcenodeAbetweentheninthandtenthiterations? 1mark
b. ExplainwhysomenodeshaveremainedthesamedistancefromsourcenodeAwhileothershaveanewdistance. 2marks
17 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 8 (4marks)Anartistwishestoconstructasculpture.ThesculpturewillbemadewithnumerousL-shapedblocksconsistingoffourcubesstucktogether.Theseblockscanonlybeplacedontopofeachotherusingtheirconnectors,shownbelow.
A
A
B
B
AA
B
B
View from top
View from side
Theartistwouldliketojoinacollectionofblockstogethersothat,uponlookingdownonthesculpture, everycellofan8×8squareofcellsiscovered,whereeachblockwouldcoverfourcells.
Describetwodifferentapproachesthatcouldbeusedbytheartisttofindapossiblearrangementofblocks.
1.
2.
2016ALGORITHMICSEXAM 18
SECTION B – continued
Question 9 (4marks)DescribethedecisionversionofthetravellingsalesmanproblemandexplainwhyitisaNon-deterministicPolynomial-time(NP)problem.
19 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 10 (4marks)TheMasterTheoremprovidesageneralsolutiontorecurrencerelationsoftheform
T n aT nb
f n a b( ) ( ), ,=
+ > > where 1 1
If f n O nd( ) ,∈ ( ) theaboverecurrencerelationhasthesolution
T n
O n
O n n
O n
a b
a b
a b
d
d
a
d
d
db
( ) log
log
=
( )( )( )
<
=
>
if
if
if
Considerthefollowingversionofmergesort,wherealistisdividedintothreesub-listsofapproximatelyequalsize.Eachofthelistsissortedrecursivelyintosub-listsandthenthesortedsub-listsaremergedintoasinglesortedlist.Assumethatthesub-listscanbemergedinlineartime.
Writearecurrencerelationforthetimecomplexityofthisversionofmergesort.StatetheappropriatecaseoftheMasterTheoremforthisversionofmergesort,includingthevaluesofa,bandd,anduseittosolvethetimecomplexity.
2016ALGORITHMICSEXAM 20
SECTION B – continued
Question 11 (5marks)Considerthefollowingalgorithmthatmightbeusedtosolveaproblemwheresolutionscanberandomlygenerated.
soln = generate random solutiontemperature = 1min_temperature = 0.01n_iterations = 100while temperature > min_temperature for i = 1 to n_iterations soln_new = generate neighbouring solution of soln if cost(soln) >= cost(soln_new) soln = soln_new else prob = (random 0 to 100)/100 if e(cost(soln)- cost(soln_new))/temperature > prob soln = soln_new endif endif endfor temperature = cooling_factor * temperatureendwhile
a. Statetherangeofvalidvaluesforcooling_factor,sothatatleast200randomsolutionsaregeneratedandthealgorithmterminates. 2marks
b. Giventhatsoln_newisgeneratedintheneighbourhoodofsoln,whyisitagoodideatosometimesreplacesolnwithsoln_newwhencost(soln) < cost(soln_new)? 1mark
c. Giveoneexampleofaproblemwhereaversionofthealgorithmaboveislikelytogiveanacceptablesolution.Describeapossiblecost(soln)forthatproblem. 2marks
21 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
Question 12 (3marks)Consideragamefortwoplayers,PlayerAandPlayerB,whichusesthreepilesofstones.Eachplayertakesaturntoremoveasmanystonesastheywishfromoneofthepiles.Theobjectofthegameistomakeanopponentpickupthelaststone.Supposethatduringthegamethethreepilesofstonesconsistofonestone,twostonesandonestone,anditisPlayerA’sturn.
Usingtheminimaxalgorithm,completethefollowinggametreeuntilitdeterminesthemovePlayerAshouldmaketoguaranteethattheywin.
(1,2,1)
After A’s move (0,2,1) (1,1,1) (1,0,1) (1,2,0)
2016ALGORITHMICSEXAM 22
SECTION B – Question 13–continued
Question 13 (7marks)Belowisagraphrepresentationofapossiblewayinwhichacollectionofcomputerscanbeconnected.Eachcomputerislabelledwithaletterandisanodeinthegraph.Cablesthatareusedtoconnectthecomputersareshownasedgesandthelengthofeachcableisgivenasanedgeweight.
10
3
7
8
6
10
9
6
10
12
139
10
87
128
5
2
S
D
A
G
C
F
H
J
B
E
I
Thecollectionofcomputersneedstobeconnectedwithcablessuchthatthefollowingconditionsaremet:• Condition1:Therearenocycles.• Condition2:TheshortestlengthofcablingisusedfromS,thesource,toeveryothercomputer
whilethetotalcablelengthforthewholenetworkisthesmallestpossiblelength.
a. DrawthegraphproducedbyPrim’salgorithmandindicatethecondition(s)thatthegraphmeets. 2marks
Condition(s)met
AS
D
G
C
F
H
J
B
E
I
23 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
b. DrawthegraphproducedbyDijkstra’salgorithmandindicatethecondition(s)thatthegraphmeets. 2marks
Condition(s)met
AS
D
G
C
F
H
J
B
E
I
c. IsthereamodificationtoDijkstra’salgorithmthatwillallowforbothCondition1andCondition2tobemet?Explainyouranswer. 3marks
2016ALGORITHMICSEXAM 24
SECTION B – Question 14–continued
Question 14 (8marks)Considerthefollowingtableofdistancesbetweenschools.
School 1 School 2 Distance
A B 10km
A C 8km
B C 5km
C E 3km
B D 1km
D E 9km
a. Drawagraphthatwouldrepresentthisdataandindicatehowtheschoolsanddistancesarerepresentedinthegraphdrawn. 3marks
Howtheschoolsarerepresented
Howthedistancesarerepresented
25 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
b. GertywantstowalkfromSchoolAtoSchoolD,beginningatSchoolA,andwillalwayschoosetowalktotheclosestschool.
WhatdistancedoesGertycoverifsheneverrevisitsaschool? 1mark
c. ThereisashorterpathforGertytogetfromSchoolAtoSchoolD.
Whatisthatpath? 1mark
d. Nedisinterestedinconnectingalloftheseschoolswithfibre-opticcableforeasyvideoconferencing.
Assumingthateachschoolrequiresalengthofcableequaltothedistancebetweentheschools,whatistheshortesttotallengthofcablerequiredtoconnectalloftheschools? 1mark
e. SamhastowalkbetweenSchoolAandsomeotherschool.Foreveryschoolhepasses,hestopsandgivestheprincipalatthatschooloneapple.ItcostsSam$2foreachkilometretravelledand$1foreachapplethathegivesout.
Howwouldtheproblembemodelledsothatasingle-sourceshortestpathalgorithmcouldbeusedtodeterminethelowestcostforSamtotraveltoeachschoolstartingatSchoolA? 2marks
2016ALGORITHMICSEXAM 26
SECTION B – Question 15–continued
Question 15 (8marks)Wallythewasherusesaspecificapproachtowashabasketofclothes.Hebeginsbydividingtheclothesintotwosmallerbasketsandwashesthefirstbasketofclothesusinghisspecificapproach.Oncehehaswashedalloftheclothesinthatbasket,hethenwashesthesecondbasketofclothesusingthesameapproach.
a. Writethepseudocodeforanalgorithm,washClothes(basket),thatdescribesWally’srecursivewashingsystem. 2marks
Whenthewashinghasbeencompleted,Wallyhastomatchupeachpairofwashedsocks.
b. Writethepseudocodeforanalgorithm,findMatch(sock, sockList),thatwilllookthroughalistofsocks,sockList,toreturnamatchingpairforagivensock,sock.Allsocksareuniquepairs. 3marks
27 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
c. AssumethatfindMatch(sock, sockList)existsandthatthereisaremovePair(sockPair, sockList)algorithmthatwillreturnsockListwithoutthegivenpairofsocks,sockPair.
Writethepseudocodeforatail-recursivealgorithmthattakesalistofsocksasinputandreturnsallpairsofmatchingsocks. 3marks
2016ALGORITHMICSEXAM 28
SECTION B – Question 16–continued
Question 16 (9marks)Toreviseherstudies,Trudiplanstodosixtestpapersinarowwithoutsleep.Trudiisveryparticularaboutherstudyenvironmentandinsiststhattherebeonlythreestacksoftests:incompletetests,completetestsandmarkedtests.Shemayalsohaveasingletestonherdesk.Trudibeginswiththefirsttestonthestackofincompletetests,doesthetestandthenplacesitontopofthestackofcompletetests.Onceallofthetestsarecomplete,shethenmarksthembytakingatestfromthetopofthecompletestack,markingitandplacingitonthestackofmarkedtests.
a. AssumingeachstackoftestsismodelledasastackADTwiththeusualoperations,writethepseudocodeforanalgorithmthatbestrepresentsTrudi’sstudysession. 4marks
b. HowmanypopoperationswillbeexecutedforTrudi’ssixtests? 1mark
c. Ingeneral,iftherearentests,howmanypopoperationswillbeexecuted? 1mark
29 2016ALGORITHMICSEXAM
SECTION B – continuedTURN OVER
d. AfterTrudihasmarkedallsixtests,shewantstofindthehighest-scoringtestbymovingtestsfromthemarkedstackbacktothecompletestack.
WritethepseudocodeforanalgorithmthatwouldfindsuchatestwhileobeyingTrudi’sconstraints,asindicatedintheintroductiontothisquestion. 3marks
2016ALGORITHMICSEXAM 30
END OF QUESTION AND ANSWER BOOK
Question 17 (6marks)JohnSearlearguesagainstthepositionofstrongartificialintelligence(AI)byusingtheChineseRoomArgument.
DiscusstwostandardresponsestoSearle’sChineseRoomArgument.