2018 Algorithmics Written examination · A correct answer scores 1; an incorrect answer scores 0....

Post on 30-Jan-2020

12 views 0 download

Transcript of 2018 Algorithmics Written examination · A correct answer scores 1; an incorrect answer scores 0....

ALGORITHMICS (HESS)Written examination

Tuesday 20 November 2018 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 18 18 80

Total 100

• Studentsarepermittedtobringintotheexaminationroom:pens,pencils,highlighters,erasers,sharpeners,rulersandonescientificcalculator.

• StudentsareNOTpermittedtobringintotheexaminationroom:blanksheetsofpaperand/orcorrectionfluid/tape.

Materials supplied• Questionandanswerbookof23pages• 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.

©VICTORIANCURRICULUMANDASSESSMENTAUTHORITY2018

SUPERVISOR TO ATTACH PROCESSING LABEL HEREVictorian Certificate of Education 2018

STUDENT NUMBER

Letter

2018ALGORITHMICSEXAM 2

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 1Whichmethodormethodscanbeusedtocheckforthecorrectnessofalgorithms?A. inductiononlyB. contradictiononlyC. inductionandcontradictionD. oncewritten,analgorithmisalreadyknowntobecorrect

Question 2ArequirementofCobham’sthesisisthatitA. assumesallPproblemsareeasyandallNPproblemsarehard.B. onlyconsidersalgorithmsthataredeterminedtobepracticallyfeasible.C. considersthesizeoftheinputtobethemostimportantcomponentforsolvability.D. considersconstantfactorsandlower-ordertermsasimportantcomponentsforsolvability.

Question 3Amanagerisattemptingtocoordinateseveralimpatientcustomerswaitinginline.Tobefairesttothecustomers,whichabstractdatatype(ADT)shouldthemanagernot use?A. decisiontreeB. directedlistC. queueD. stack

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 2018ALGORITHMICSEXAM

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 4Considerthefollowinggraph.

Whichofthefollowingpropertiesdoesthisgraphhave?A. directedandacyclicB. cyclicandweightedC. cyclicandfullyconnectedD. non-directedandnon-connected

Question 5WhichoneofthefollowingmustexistinthedefinitionofanADT?A. auniqueidentifierB. asetofoperationsC. aconcreterepresentationofdataD. theimplementationofoperations

Question 6WhichoneofthefollowingbeststatesthedifferencebetweenalistADTandadictionaryADT?A. Findingtheminimumiteminasortedlistisusuallyfasterthanfindingtheminimumitemina

dictionary.B. Findingthemaximumiteminadictionaryisusuallyfasterthanfindingthemaximumiteminasorted

list.C. Alistcanhaveitsvaluesaccessedviaanintegerindex,whileadictionarycannot.D. PrioritiesaredefinedwithinalistADT,whileadictionaryhasnoprioritiesintheADT.

Question 7Whentestingtofindoutwhetheragraphhasmultipleconnectedcomponents,whichoneofthefollowingmodificationstoabasicimplementationofPrim’salgorithmisthemostappropriate?A. Choosethemaximumweightededgetoconnectanodetothegrowingtree.B. RunPrim’salgorithmoneverynodeandkeeptrackofuniquesetsofnodes.C. Deleteallexistingedgesoftheexistinggraphandcreatenewedgestoconnecteachnode.D. NomodificationsneedtotakeplaceasPrim’salgorithmcanalreadytestformultipledisconnected

components.

2018ALGORITHMICSEXAM 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

Question 8ForwhichoneofthefollowinggraphswouldtheFloyd-Warshallalgorithmreturnall-pairshortestpaths?

A

CB

–2–1

–3

A

CB

2–4

1

A B

C D

–2

2

3 –2

A. B.

C. D.A B

C D

–2

2

–1 –41 1

Question 9Assumequicksortalwayschoosestherightmostelementasapivotwhencreatingpartitions.Thesortingmaintainstherelativeorderofelementswhilepartitioningandstopstherecursionattheemptyarray.Giventhearray{1,2,3,4,5,6,7,8},howmanypivotswillbechosenbeforethealgorithmreturnsasortedarray?A. 0B. 1C. 3D. 8

Question 10Considerthefollowingpseudocodeforthealgorithmunknown(x),wherexisanodeofagraph.

Algorithm unknown(x) Let x.discovered = True

For eachNode in x.adjacentNodes

If eachNode.discovered is not True Then

unknown(eachNode)

EndIf

EndFor

Whichalgorithmdoesthepseudocodebestrepresent?A. best-firstsearchB. depth-firstsearchC. bruteforcesearchD. breadth-firstsearch

5 2018ALGORITHMICSEXAM

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 11

cloud

10010 1

1

1100

10

WhichoneofthefollowingADTswouldbebestsuitedtomodelthenetworktopologydiagramshownabove?A. aweighted,directedgraphB. astackwithkeysC. adirectedgraphD. anarray

Use the following information to answer Questions 12 and 13.Considerthefollowingthreealgorithms,whichalloperateoninputsofsizenelements,andtheirBig-OorBig-Θresourcerequirements:• AlgorithmA:O(n)worstcasetime• AlgorithmB:Θ(2n)bestcasetime• AlgorithmC:Θ(nlogn + n)bestcasetimeandworstcasetime

Question 12WhichoneofthefollowingstatementsaboutalgorithmsA,BandCiscorrect?A. AlgorithmsAandBareincomplexityclassP.B. AlgorithmsBandCareincomplexityclassP.C. AlgorithmsAandCareincomplexityclassP.D. AlgorithmsAandCarenotincomplexityclassP.

Question 13WhichoneofthefollowingstatementsaboutalgorithmsA,BandCiscorrect?A. NoalgorithmwillterminateinO(1)timeonanylargeninputs.B. AlgorithmAcouldterminateinO(1)timeonsomelargeninputs.C. AlgorithmBcouldterminateinO(1)timeonsomelargeninputs.D. AlgorithmCcouldterminateinO(1)timeonsomelargeninputs.

2018ALGORITHMICSEXAM 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 14SameerarunsanalgorithmonthegraphbelowtocomputeapathfromAtoB.Thealgorithmbecomestrappedinacycle.

B C

A

WhichoneofthefollowingalgorithmshasSameeraused?A. PageRankalgorithmB. Dijkstra’salgorithmC. breadth-firstsearchwithoutmarkingpreviousnodesD. depth-firstsearchwithoutmarkingpreviousnodes

Question 15CyclistSergeihasacleverplantowineveryracethatheenters.Hewillstartatthefrontoftheracepedallingslowlyat5km/h.Everytimesomeonecatchesuptohim,Sergeiwilldoublehisspeed.Assumingthatthemaximumspeedforanycyclistis60km/h,howmanypeoplewillcatchSergeibeforehecannotgoanyfaster?A. 2B. 3C. 4D. 5

Question 16Analgorithmtakesasetofinputsandperformscalculationsonit.Theoutputfromthealgorithmconsistsofasetofnumbersandlettersthatarerelatedtotheinitialinputs.TheoutputfromthealgorithmcanbeverifiedinworstcaseO(n2)time.Giventhisinformation,itcanbesaidthatthealgorithmisA. decidableandincomplexityclassNP.B. undecidableandincomplexityclassNP.C. decidableandincomplexityclassPandnotincomplexityclassNP.D. undecidableandincomplexityclassPandnotincomplexityclassNP.

Question 17AneuralnetworkcanbeusedtoA. findexactsolutionstocomputationallyundecidableproblems.B. demonstratethatSearle’sChineseRoomArgumenthasmerit.C. processcomplexinputswithnoknownrelationships.D. alwayssolveproblemsfasterthanDNAcomputing.

7 2018ALGORITHMICSEXAM

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 ATURN OVER

Use the following information to answer Questions 18 and 19.ThefollowingisaproofbycontradictionthatPrim’salgorithmgeneratesaminimalspanningtree(MST),withsomedetailsomitted:• LetGbeagraphwithvertices,V,andaminimalspanningtree,T*.• LetTbeaspanningtreegeneratedbyPrim’salgorithmongraphG.• AssumeT≠T*.Lettheedge(u,v)beinTbutnotinT*.• When(u,v)wasaddedtoTbyPrim’salgorithm,itwastheminimumedgecrossingfromthesetof

vertices,S,thathadalreadybeenaddedtoT,tothesetofvertices,V – S,thathadnotbeenaddedtoT.• Let(x,y)beanedgeonthepathfromu to vinT*suchthatxisinSandyisinV – S.• Formanewtree,T**,byadding(u,v)toT*andremoving(x,y)fromT*.

Question 18Whichoneofthefollowingstatementsisnot correct?A. Theedge(u,v)existsbecauseT≠T*.B. Thereisapathfromu to vinT*becauseitisaspanningtree.C. T**isnotatreebecauseadding(u,v)toT*andremoving(x,y)fromT*createsacycle.D. T**isatreebecauseadding(u,v)toT*andremoving(x, y)fromT*doesnotcreateacycle.

Question 19Whichoneofthefollowingstatementsgeneratesthecontradictionneededtocompletetheproof?A. T**hasahigherweightthanT*,thusT*couldnotbetheMSTofG.B. T**hasalowerweightthanT*,thusT*couldnotbetheMSTofG.C. T**isnotatree,thusT*couldnotbetheMSTofG.D. T**isnotatree,thusT*istheMSTofG.

Question 20Simulatedannealinghasbeensuggestedasausefultechniquetocomputeaglobalminimumrainfalloveralargesetofrainfalldata.Whichheuristicappliedtosimulatedannealingismorelikelytoreturnaglobalminimumrainfall?A. increasetheprobabilityofchoosingaworsesolutionatrandomasrunningtimeincreasesB. decreasetheprobabilityofchoosingaworsesolutionatrandomasrunningtimeincreasesC. allowthesystemtemperaturetocoolquicklytofindasolutioninashortamountoftimeD. keepthesystemataconstanttemperaturetofindthebestsolutionwithinashortamountoftime

2018ALGORITHMICSEXAM 8

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 1 (2marks)DescribeonesimilarityandonedifferencebetweenaTuringmachineandamoderncomputer.

Question 2 (4marks)Eliseneedstouseapriorityqueueabstractdatatype(ADT).

WriteapriorityqueueADTspecificationforElise.

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>

9 2018ALGORITHMICSEXAM

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 3 (4marks)Thefollowingalgorithmfindsthemaximumelementinalist.

Algorithm FIND_MAX(L): Input: L, a non-empty list of elements

If L has only one element

return first element of L as the maximum

EndIf

m = FIND_MAX(L without the first element)

If m is greater than the first element in L

return m

Else

return the first element of L

EndIf

a. Writearecurrencerelationanditssolutiontodescribetheworstcaserunningtimeofthealgorithmwhenthelistcontainsnelements. 3marks

b. WouldtheBig-Oforthebestcaserunningtimeofthealgorithmbesmallerthantheworstcaserunningtimeofthealgorithm?Justifyyouranswer. 1mark

2018ALGORITHMICSEXAM 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

SECTION B – continued

Question 4 (2marks)Considerthefollowingrecurrencerelations.

S nS n n

O

n

n

T nT n O n

O

( )( )

( )( )

(

=

+

>

<

=

+

23

3

1

3

4

22

1

if

))

>

<

if n

n

1

2

a. WhatistheBig-OsolutiontoS(n)? 1mark

b. WhatistheBig-OsolutiontoT(n)? 1mark

Question 5 (3marks)Maryaminvestsincompaniesonthestockmarket.Sheiscurrentlyconsidering50potentialcompaniesshecaninvestinandhasestimatedthepotentialprofitsheislikelytoreceivefromeachcompanyoverthenext12months.TheinvestmentineachcompanyhasaninitialcostandMaryamhasafixedbudgetthatshecannotexceed.

DescribeadynamicprogrammingalgorithmthatMaryamcanusetoselectasetofcompaniestoinvestinthatwillprovidemaximumprofitforherbudget.

11 2018ALGORITHMICSEXAM

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 6 (5marks)Anewshoppingcentrehasbeenbuiltandhasattractedmanycustomers.Thecentre’smanagementhasnotedthatmanyofthesecustomersaregettinglostwithintheshoppingcentre.Thecentre’smanagementwantstodesignandbuildaninteractivemapapplicationthatwillallowcustomerstofindtheirwaytoeachshopfromfixedinformationkiosksaroundtheshoppingcentre.

a. NameandjustifyagraphADTthatwouldbestsuittheinteractivemapapplication. 3marks

b. Thecentre’smanagementhasdecidedtoinstallanadditionalinformationkiosk.

Explainhowtheadditionalinformationkioskcouldbeintegratedwithintheinteractivemapapplication.WhatchangestothegraphADTnamedinpart a.wouldhavetooccur? 2marks

2018ALGORITHMICSEXAM 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 – continued

Question 7 (4marks)Considerthedecisiontreebelow.

weekday weekend

time > 9 amand time < 3 pm

time > 3 pmand time < 9 am

no homework homework

no homework homework

school sleep

sleep study

study

Representthisdecisiontreeusinglogicaloperationsinpseudocode.

13 2018ALGORITHMICSEXAM

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 8 (4marks)Proveviainductionthatthesumofthefirstnoddnumbersisthesameasn2,foralln≥1.

2018ALGORITHMICSEXAM 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 – Question 9–continued

Question 9 (9marks)Devicesthatarecapableofwirelesstransmissionarebecomingcheaperandeasiertointegrateintoexistingtechnology,suchasvacuumcleanersandrefrigerators.Thesedevicestypicallycommunicateusinganetwork.ThenetworkbelowshowsdevicesnamedA–O.

Grid 1 2 3 4 5 6 7 8 9

a

b

c

d

e

f

g

h

i

O

C

F

E

I

G

D

JH

KB

A

M

N

L

Thenetworkabovehasthefollowingconditions:• Eachdeviceisawareofitscoordinatesandthereisacompletelistofdevices.• Eachsquarerepresentsa50m×50marea.• Forsuccessfulconnectionoverwirelesstransmission,devicesmustbewithinrange:twosquares

verticallyorhorizontallyandonesquarediagonally.Forexample,deviceAcancommunicatewiththosesquareswithanunderscore.

• Eachdevicecanrelaydatabetweennodeswithinrange.Forexample,deviceAcancommunicatewithdeviceE,whichcanthencommunicatewithdeviceF.

• Eachdevicecanreturntemperaturevaluesmeasuredwithinitssquare.

a. Whichdevice(s)cannotsuccessfullyconnectoverwirelesstransmissionwithanyotherdevice? 1mark

15 2018ALGORITHMICSEXAM

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. DescribehowtheFloyd-Warshallalgorithmcanbeusedtocheckifalldevicescancommunicatewithanyotherdevice. 2marks

c. Writeanalgorithmtocomputetheaveragetemperatureofalldevicesinthenetwork,givenalltemperaturesinaninputlist,temperature_list.Somedevicesmaybedefectiveandreturn–255astheirtemperaturevalue.Thealgorithmshouldnotincludethesetemperaturesinthecalculation. 6marks

2018ALGORITHMICSEXAM 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 – continued

Question 10 (4marks)Joedeliversgroceriestothesamefivehouseseverydayaspartofhisdeliverybusiness.Toconservefuel,hecomputedthelengthofallpossibleroutesbetweenhishomeandthosefivehousestofindtheminimumroute.

a. HowmanyroutesdidJoecompute? 1mark

b. Joe’salgorithmtodeterminetheminimumrouteisanexampleofwhatalgorithmicdesignpattern? 1mark

c. AsJoe’sdeliverybusinessgrowsandmorehousesareaddedtothedeliverylist,willJoe’salgorithmicapproachstillbeusefulforcomputingtheoptimaldeliveryroute?Justifyyouranswer. 2marks

17 2018ALGORITHMICSEXAM

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 (4marks)Considerthefollowingalgorithmforsortingalistofintegersinascendingorder,whichmakes useofanotheralgorithmcalledSORT2.AssumethatSORT2runsinΘ(n logn)timeonalistoflengthn,unlessthelistissortedindescendingorder,inwhichcaseSORT2runsinΘ(n2)time.

Algorithm SORT(L) INPUT: L, a list of integers

Let sorted = True

For each element x except the last in L

If x is greater than its right neighbour in L

Let sorted = False

EndFor

If sorted is False Then

Return the result of SORT2(L)

Else

Return L

EndIf

a. WhatisthebestcaserunningtimeofSORT?Writedownalistof10integersthatgivesthebestcaserunningtime. 2marks

b. WhatistheworstcaserunningtimeofSORT?Writedownalistof10integersthatgivestheworstcaserunningtime. 2marks

2018ALGORITHMICSEXAM 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 – continued

Question 12 (2marks)

–5

–2 1

–2

2

1 0

A B

C D

E F

ExplainwhythegraphaboveisnotasuitableinputtoanaiveimplementationoftheBellman-Fordalgorithm.

Question 13 (3marks)DescribeDNAcomputingandexplainhowitcanbeusedasanalternativemethodofcomputation.Provideanexampleaspartofyourexplanation.

19 2018ALGORITHMICSEXAM

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 14 (9marks)Thestrategyusedforclimbingarockwallisveryimportant.Foragivenrockwall,thereisasetofnumberedhandholdsandfootholdsthatcanbechoseninsequencetoallowtheclimbertogettothetopofthewall.Longrouteswithhandholdsandfootholdsthatarespacedfarapartcancausetheclimbertotirequicklyandincreasetheirriskoffalling.Shortrouteswithcloselyspacedhandholdsandfootholdsallowclimberstopreserveenergyandmakeittothetop.YouhavebeenselectedasthestrategycoachoftheAustralianteamfortheClimbingWorldChampionships.Inparticular,youhavetoplotacourseforeachclimberoneachwall.

a. Whatinformationwouldyouneedabouteachwallandeachclimber?WhatADTwouldbebesttousetomodelthisproblem?Why? 3marks

b. WhatalgorithmwouldyouusetodeterminetheoptimalclimbingrouteusingtheADTfrompart a.?Inyouranswer,describehowyouwouldtranslatetheoutputfromyouralgorithmintomeaningfulinformationthattheclimbercoulduse.Alsoincludeanestimationofthetimecomplexityofyourapproachandhowitcomparestoabruteforceapproachtotheproblem. 6marks

2018ALGORITHMICSEXAM 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 15 (3marks)Socialmediaprofileshavebeenreceivedbyacompanythatplanstousethedatatoinferwhichusersitshouldtargetfirstinordertoinfluencelargecommunities.Thedatacontainsuserprofiles,theirlistsoffriendsandtheirpubliccomments.

Describeanalgorithmthatcouldbeusedtoidentifythemostinfluentialprofilesinthedata.

Question 16 (4marks)Bernieisdevelopingamobilerobotforanationalpark.Therobotwilltravelthroughtheparkusingexistingpathsanddepositanimalfoodatfeedingstations.Thesefeedingstationswillbechangedeveryseasontomatchthemovementofanimalsduringtheyear.Bernieiscurrentlydesigningthealgorithmthattherobotwillusetoselectthemostefficientpathitshouldtaketovisitallofthefeedingstationswhileminimisingthedistanceittravels.

WhatisthebestalgorithmforBernietousetodecidetheorderinwhichtherobotwillvisiteachfeedingstation?Willitguaranteeanoptimalsolution?Explainwhyorwhynot.

21 2018ALGORITHMICSEXAM

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 17 (4marks)Afarmersharesafieldwithanotherfarmer.Everyyeareachfarmercansell10cowsandreducetheirincomeby10%orbuy10cowsandincreasetheirincomeby10%ordonothing.Atthebeginningofeachyear,theavailableresourcesinthefield,asapercentage,changeby100minusthetotalnumberofcows.Forexample,assumethatthefieldhas100%resourcesand,atthebeginningoftheyear,Farmer1has50cowsandFarmer2has70cows,thustheresourceschangeto80%.Ifnextyearthetotalnumberofcowsis110,theresourceschangeto70%.Ifnextyearthenumberofcowsis90,theresourceschangeto80%.Iftheavailableresourcesatthebeginningofayeardropbelow50%,allcowsmustberemovedandbothfarmerslosetheirbusinesses.

Describeanalgorithmthatwillselectastrategythatmaximisesonefarmer’sincomeattheendoftwoyears,withoutlosingallofthisfarmer’scows.

2018ALGORITHMICSEXAM 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 18–continued

Question 18 (10marks)Twopirates,MontyandBlackbeard,havedecidedtodividetheirfortunes.MontymakesthefollowingpropositiontoBlackbeard:Choosebetweentakingthesquaremadeofgoldwhosesideisthehypotenuse(sidec)oftheright-angletriangleorthetwosquaresmadeofgoldwhosesidesareadjacenttotheright-angletriangle(sidesaandb),asshowninthediagrambelow.

c b

a

IfBlackbearddecidestotakethesquarewiththehypotenuse(sidec),hemustgiveacertainpercentageofthegoldtoMonty.

a. Writeanalgorithm,square_area,inpseudocodethatwillreturntheareaofanygoldensquare. 2marks

23 2018ALGORITHMICSEXAM

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

b. Assumesquare_areaexists.WriteanalgorithminpseudocodethatwilldeterminethebestdecisionforBlackbeardtomakeinordertomaximisetheamountofgoldhereceives.IfBlackbeardshouldchoosethesquarewiththehypotenuse(sidec)thenthealgorithmshouldreturnTrue,otherwiseitshouldreturnFalse. 4marks

c. WhatisthebestdecisionforBlackbeardtomaketomaximisetheamountofgoldhereceives?Justifyyouranswer. 2marks

d. Insteadofsquaresmadeofgold,MontyandBlackbeardmustsharecubesmadeofgold.

WhatisthebestdecisionforBlackbeardtomakeinthisinstance?Justifyyouranswer. 2marks