Sothetotalnumberofavailablechoicesforusaswetrytoconstruct a newsubstancefromthisgivenarrayistwotimestwo, whichisfour.
Thisnumberrighthereonit's thesamewhenwe'retryingtoconstruct a subsetoutofanarrayoffanditemsaswell.
Therearetwochoicesthatwecouldpotentiallymakeforeachitemonsincetheir n itemsthere, too, tothepartyandpotentialchoicesortwotothepartofandpotentialsubsets.
Sotoinitializethisinitialemptysetatthebeginningoffallsubsets, wecaninitializeHonore, whoselengthisthesameasgiving a racelengthorgiven a raythatlengthonthecontentcouldbeanythingbuthecan't be, forexample, nono.
Ifthegiven a raiselengthistooandwe'regoingtodefineahhelperfunction, whichisgoingtocallitselfrecursiveLee, we'regoingtocallitHelper, andit's goingtotakethreeargumentsgivenarray, whichisthegivenarraywhichneverchangesSubset, whichrepresentsthestateofthecurrentsubstancethatwe'reconstructing.
So, forexample, thisemptysubsetorthissetofonerepresentitinanarrayformaton I isgoingtorepresenttheindexofthecurrentitemthatwe'reexamining.
Soif I isequaltozero, forexample, thatmeansthatwe'retryingtodecideifweshouldincludethisiteminthecurrentsubsetthatwe'retryingtoconstruct.
Andif I isequaltoone, thatmeansthatwe'recurrentlyexaminingthisitematthenextone.
Nowthefirstthingweneedtodointhehelperfunctionisweneedtocheckif I isequaltogiven a raiselengthor a given a ratethatlength.
Ifthat's thecase, forexample, inthisexample, if I isequaltotwo, whichisgiven a racelength, thatwouldmeanthateyespointingoutsideovary, whichmeanswealreadywentthroughthiswholearrayandfinishedconstructingoneofthesesubsets.
Nowtorepresentthe 1st 2 recursivecallwherewedon't addthecurrentitemthatwe'reexaminingtothesubset, wecanjustsettheitematthecurrentindexandthesubsetarraytonowwecandothiswithsubsetsquarebrackets I equalsnowon.
Afterthat, wecancallithelpformepersonallywithgivenarraysubset, whichistheupdateisupset I plusonetogotothenextindexandtorepresentthesecondbecausehewouldcallwherewedoaddthecurrentitemthatwe'reexaminingtothesubset.
Wecansettheitematthenext I inthesubsetRaytothecurrentitem, forexample, towecandothiswith, ofcourse, subsetsquarebrackets.
I Eco's given a racecarbuckets I andthenjustlikebeforecalledHelper.
Again, wecurseuglywithgiven a raceupsetonmyplusone, andthat's mysolution.
Butwhat's thebenefitofusinganarrayinsteadof a setstructuretorepresenteachsubset?
Thebenefitisthatitbecomeseasiertokeeptrackofthecurrentstateofthesubsetbyusinganarrayinsteadof a setstructure.
Forexample, Subsetmightstartatnow.
No, ButaswegodownthisRykerAsiantreeatthispointwhenwe'rehere, you'llbenow, too.