You'rewelcometotakeasmuchoraslittletimewithinthattimeframetoworkinthetestasyoulike a CZlongasyoumeetthatfinaldeadlineofturninginthetestbyFriday, theeighthat 11 59 PMandyou'lldosobyturninginthetestby a gradescopeinmuchthesamewaythatyou'vebeenturninginquizzeswhereyouupload a pdfofyourresponses, you'llchoose, whichpaysitpages.
Yeah, Whencanyouexpectresultsbackafterturninginthetestusuallywilltrytogetthetestsgradedwithin a coupleofdays a weekatmostotherquestionsabouttestlogistics.
Attheendofeveryquestioninthetestwillbe a debriefingsection, whichwillaskyouwhichresourceisyouusedinordertoanswerthequestion.
Soanyresourceisthatyoutookadvantageofwhetherthewebsiteyoulookeduponlineor a lectureslidejustreferencedthatinyourresponsetothattestquestion, justthatwehavethatinformationaswell.
Ingeneral, wesayyouwillprobablybespendinghalf a now, er a littlemorethanhalfanhourperquestion.
Andyoucanlookbackatpastyearstestingquizzes, andusuallythey'reintherangeoflike, 8 to 12 questionsorsosomewhereinthatrange.
Allright.
So, a coupleofways, intermsofpreparationforthetestintermsofwhattodofirstandforemost I wouldrecommendreviewinganyofthelectureresourceissothatincludesthelecturevideo, butalsolecturenotes, anyofthesourcecodeexamplestheDaviddemonstratedinlecture.
Sopastyears, testquizzesandtheirsolutionsareavailableonlineTomb, andthen I'd recommendtaking a lookattheproblem.
Sincetheproblemshavespecificationsareonline.
Inadditiontosamplestaffsolutionsthatyoucantake a lookatandthosethey'reoftenhelpfulresourcesaswell, justtogiveyou a senseforthetypesofproblemsthatyouwereaskedtosolveduringCIA 50 sofarandthereforethetypesofthingswell, youmightbethinkingaboutoverthecourseofthetestonthen.
Ofcourse, a greatthingtodoforthetestpreparationiswhatyou'realldoinghere.
Therehavebeen a numberofdifferentthemesthathavecomeupagainandagain, andoneofthebigthingsthatwetrytoemphasizeaswethinkaboutpreparingforthetestisthinkingaboutthosebigthemesandhowit's connected.
Sothefirstofwhichisthisideaofabstractiontheideathatonceyou'vebeenabletounderstandtheunderlyingdetailsofsomething, youcanbegintothinkaboutitat a higherlevelwithoutneedingtoworryaboutthoseunderlyingdetails.
Thenwesawthatinmorerecentweekswiththingslikedatastructures, wheredatastructurescanoftenbethoughtofabstractionsofherlowerlevelideasorevenmoremodernprogramminglanguageslikePythonthatintroduce a lotofnewabstractions.
Easierwaysofimplementingparticulartasksincomparisonto a languagelikeseewhereyoudidn't needtoworryabout a lotofthoseunderlyingdetailsasyouwentaboutdesigningthoseprograms.
AlgorithmsthereAnotherbigthemethinkingaboutIfyou'regiven a problem, whatarethestepbystepinstructionsyoumightuseinordertosolvethatproblem?
Andsowe'llbetalkingabout a coupleofthosetodayanddefinitelyfeelfreetoaskaboutthemaswell.
Andthen, finally, a bigthemehasbeentradeofftheideathatanytimewegetsomethingincomputerscience, itoftencomesat a costthatanalgorithmthatmightbefastermightcomeatthecostofusingmorememoryoranalgorithmthatmightallowforcertainoperationsmightcomeatthecostofbeing a littlebitslower.
ThetwototheZerosplacecouldbeeither a zeroor a one, representingquiteliterally, a zeroor a oneandsoforth, allthewayuptotwototheseventhforeightbitesforeightbitstomakeonebite.
YouhadtoimporttheCS 50 library, thensay, youknow, askforthenameof a personinquotesrightafterwards.
Andthentheywouldtypein a stringtothecomputer, whichyourcomputerwiththemstoreinwhichevervariableyouusedtheretheygetstringdocumentation, andtheactualcodebehindhowitworksissomewhereinthe C s ofthelibrary.
Youcouldfinditifyouwantedit, butyoudidn't actuallyneedtoknowhowitwasimplementingsuch a thinginordertouseitcorrectly.
A lotofthepowerofcomputersciencesreusingthingsthatotherpeoplehavewrittenbefore.
Andsoherewethinkabout a lotofthosesortsofthingsthatyouusedinthefirstweeksofthecourseasblackboxalgorithms.
Ittakesaninput.
Inthiscase, ittook a stringfromtheuser, anditgivesyouyourdesiredoutputvariablethatholdsthatstringquestionsaboutthisblackboxstructurequote.
That's a sortoftoolthatyouwouldusemoneyothertimesandseeinpythonandbeyondconditionsholdBooleanstatements, andsoyouhaveifs.
L ifselseelse's don't holdanythingbecausethey'reyourultimatefinalthingthat's goingtohappeninyourcode.
However, here, youknowthatyou'reifthenconditionstakensomethingcalled a poolingexpression.
Itsays.
Eitheryouknow, if a equals B.
If A and B arebothtrue, um, oroperators, notoperators.
Youwouldlearnaboutthesyntaxdraftleave.
Howwouldyou?
Youwouldusethosethingsandsee, andinPythonlater, youknowthattheychange a littlebitthedoubleampersandforauntandseetheactualword.
AndinPython, however, theideaisalwaysthesame, andyouknowthatyouwereabletocompareanynumberofthingsofthesametypeinthisway, loopsand a similarveinrepresentedandscratch.
Withtheseyellowblocks, itcanrepeatsomething a certainnumberoftimesyoulearnedaboutwhileloopsaboutdowhileloopsetcetera, andtheyareabletorepeatactionsanynumberoftimesthatyoudefine.
WhatwereyouguysgottheopportunitytostartcodingintheCIAusingSeeyourfirstprogramminglanguageandtheveryfirstprogramthatyoulikelywrotewasthisoneyouincludedstandardiodot h andintoMainevoidYouthenwrotePrint F HelloWorldintoMaineisoff.
Thenif I typedmynameEmmainwhenprompted, thennamewouldbe a variablethatheldthestringEmmaorthearrayofcharacters.
Emma.
UmAndthenyoucouldprintusingthisintaxwiththepercent s tohold a spacefor a stringessentiallyandthenpassinthevariablenameforconditionalistheywouldlooksomethinglikethis.
Thisisveryfamiliartoyouaswell.
Hewouldwriteifexcellenceandwineprintthis X isgreaterthanwhyelse, etcetera.
Youknowthatifyouhaveanultimatecondition, thenyouputitinanelsewithout a booleanexpressionbecauseanythingelsewouldfallunderthat, um, conditionautomaticallybynotsatisfyinganyofthepreviousones.
Questionsaboutanyofthesethingssofarandseesyntax.
You'reallexperts.
I know.
Sothenifwemoveforwardintoloops, youwouldwriteforantiequalzero I lessthan 50 I plusplushowmanytimeswiththatprintsomethingordotheactioninthemiddle 50 becausethat's howyousaidit.
Loopsalsocanbelike a wildloop, sothisonedoesn't directlygenerateoverwith.
I youcanusesomethinglikethisifyoudon't actuallyneedthatvalueof I toinfluencetheinputsthatyou'regoingthrough.
Weknowthatfor a lotofourprogramsearlier, likeifyouthinkaboutmovingthroughanimageyouneededthat I valueinordertoorientyourselfwithin a picture, etcetera.
Butsometimesyoujustwanttodoanaction a certainnumberoftimes.
Thenyoucouldhave a wildlooporeven a do I loop, whichdoessomethingaslongasanotherconditionistrue.
Somethingelsethatyousawwithmaybegettinginputsfromtheuserthatmatch a certainnumberofconstraintsthatyouwatched a setquestionsaboutloopsgreat.
I wantedtogiveyouallanopportunitytocoughhimovermanytimeshewouldwish, andthenitwouldmake a lotofsensetoehavethisfunctionseparatedsothat I didn't havetorepeatthiscodeeverytime.
I wouldjusthavetorepeatgettinganintruderandfromyouindividuallyandthenrunningthecallfunctionwithInterDuran.
Anyquestionsaboutfunctions?
Yeah, somethingtodo.
Youliketofindit, likeattheend, Butsomethingnoticereferencecodethatyouwhat's so I thinkthequestionsaboutstructuringyourcodesothatcoat, likeifyourmainfunctionisaboveit, understandsthatthefunctioningthislaterandsoyoucandeclarefunctionsearlieronsothatyoucanusethemsoyoudon't getlikeweird C syntaxEversinordertousethingsintheorderthatyouwantthemwhiletheymightbecreatedlater, becausethiswouldprobablydownlowerinyourcoatandyourmainfunctionwouldbeaboveit.
Soifyouknowthatsomethingismessedupin a fourloop, youcanprinteverysinglevariableusingthatfourloopandusuallytellbyprocessofeliminationandsomecleverprintingwhereyou'regoingwrong.
Yeah, sopythonis a littlebitdifferentintermsofcompiling, becauseyoudon't Yeah, we'lltalkaboutthis a littlemorewhenwegettohighphone.
Wanttobein a coupleofsides?
Butinshort, thisistheprocessforseen.
Thingslook a littledifferentforpythonbecausePythoniswhatwewouldcallaninterpretedlanguageasopposedto a compiledlanguagelikeseem.
AndsothewaythatyourunPythonprogramsis a littlebitdifferent, butwe'llgetthere.
It's a littlefuzziercauseyoudon't impactmemorydirectly, andthingsare a littlebitmoreabstracted.
Somovingonfromdebugging, we'lltalkabout a rateso a razor, a superpowerfuldatastructure, you'reabletostorethingsincontinuousblocksofmemory, andsoifyouwanttobesurethatthingsarerightnexttoeachotherin a waythat's easilyaccessibleand, uh, youcoulduseindexinginordertogettoitall.
Andthenwehad a pluralitywhereyoupassedinthenamesofthecandidatesthemselvestothecommandline.
Andsohere, for a plurality, weknowthatwehaveindarkseaandstring.
RV, whichisthedarksea, is a numberofargumentsthatyoupassedin, includingthenameofthefileitselfand R.
V isthearrayoftheinputstothatfile.
Andsohere.
WhatwouldourCSIbeforthiscalled a pluralityforandyourarraywouldbe, what I'lltalk a littlelouder.
Yes, Andsothenit's directlythethingsthatyoutypedinthesefourdistinctstringsofcharactersandthenthearksee, is a numberofthingsyoutypedin, whichinthiscasewouldbefour.
Soifyouhadanarray, if I putintothatarrayofwhatevertheoneofvalues 123455 wouldbethefourthtechnicallyindexofthatarray, therewouldn't be a nocharacterattheend.
Andnowthatwehad a lotinfunctionsandnowthatwehaveallthiscapability, thenextstepishowdoweusethatinordertosolveproblems?
Andsothiswaswhatwethreeofusabout.
Wethoughtitwasallaboutalgorithmstryingtofigureouthowdowewritecodethatisabletotaketheseinputsandsolvesomesortofproblemintheproblemsthatyouusethisinordertoimplement a varietyofdifferentelectionalgorithms.
So a simple, poor, outpluralityelectionthatcountedup, whohasthemostnumberofvotesbutthenlookingatmoresophisticatedalgorithmslike a runoffelectionortheTideMenelectionmethodthatrun a littlemoreof a complexalgorithmtotryandfigureoutwhothewinnerofanelectionis.
But a lectureWetalkedabout a coupleofstrategiesforhowtorepresentinformationandthenhowyouusethatinformationinsideofanalgorithm.
Butifweneededtorepresentothertypeslikewewantedtorepresent, Ah, person, forexample, iswesawinlectureorintheproblemsthatyousawtherepresentationof a candidateas a brandnewtype.
Inlaterproblemsets, yousaw a typeforRGBtriplesfor a tripleofred, greenandblueinordertostore a pixelofinformation.
Andsowhatwehadherewasthedefinitionof a newtypecalledpersonwherethewaythesyntaxworkedasweusethetypedeafkeywordtosay, letmehave a newtypewith a particularname.
Whatisthattype?
Well, thetypeis a structureor a struck, whereyoucanthinkof a struckas a wayofencompassingmultipledifferentpiecesortypesofinformationinto a singleunitinto a singlevalue.
Andsoinsideof a personwe'regoingtorepresent a personusingtwopiecesofinformation.
Everypersonhas a stringcallednameandeveryone.
Everypersonhas a stringcallednumberthatrepresentstheirphonenumber, forexample, andrecallthatweused a stringinsteadofaninchbecausewewantedtobeabletorepresentmaybehyphensorparenthesesthatmighthavebeenincludedinsideofthephonenumber.
Weincluded a fieldinherefor a numberofvotes, butinshortwecouldtakewhateverdatawewanted a storein, compassitalltogetherinsideof a structure, andthencallthatnewtype a personorwhatevertypewewanted, andthatgaveustheabilitytomoreabstractlyrepresenttheideaof a personor a pixelsomewhereinsideofourprogram.
Andsotherewere a numberofdifferentwaysthatwecouldsearchforsomething.
Butonewaywastosay, forexample, ifwehave a biglistofunsortedthings, wecoulduselinearsearchtosay, like, startedtheveryfirstelementinthearrayandthenlookwhatelementat a timeinordertotrytofindit.
Andthensomeoneremindme, likeinrunningtime, Whatwasthebig O oflinearsearch?
Howefficientislinear?
Search a searchforsomething?
Yeah.
Oh, of n yeah, lineartimetobeabletosearchforsomethingbig O notationrecalls, sortofencodestheideaofwhatistheworstcaseortheupperboundonhowlongitmighttakeforthisalgorithmtorun.
Andso, inthecaseoflinearsearch, itmighttakeus.
Ifwehaveanyelementsinsideofthearraythatwe'relookingforhim, itmighttakeusendstepsinordertolookthroughit, andsothatwasonemethodofsearchingforsomethingandwhatwas a moreefficientwaytosearchforsomethinginsideofanarray.
Andalso, asweintroducedispartofbinarysearchBig o notationinthesanitationweusefordescribingtheruntimeofalgorithmshowlongittakesforanalgorithmtorun.
Whatquestionsdoyouhaveaboutthat?
Viggonotationalgorithmsruntime.
Allright, WefeelOKaboutthat.
Inthatcaserelatedtobig O notationwithanothernotation.
SowhileBig o describestheupperboundontherunningtimeofanyalgorithm, therewasanothernotationweusedcalledBigOmega, whichwasallaboutthelowerboundontheruntimeofanalgorithm.
We'rethebigideaofBubblesortisifwehave a bigarraywheretheelementsairunsorted.
Welookattheelementsinthatarraytwoat a time, lookat a pairofelementsandinassortedarray, theelementontheleftshouldalwaysbelessthanorequaltotheelementontherightinanypairofelements.
Sothealgorithmiswe'regoingtorepeatthisandminusonetimeswillcomebacktowhyandminusoneinjust a moment.
Butwe'regoingtorepeatthisfrom I fromzeroto n minustwo.
Sofromtheveryfirstelementinthearrayandupuntilthesecondtolastelementinthearrayrecalledthatifwehaveanarraythathas n elements, thefirstelementiselementzero.
Thelastelementisandminusone a littlebittrickybecauseyouhavetostartcountingitzero.
Butforeachelement, I we'regonnalookatElement I andIIplusone, andifthey'reoutoforder, we'regoingtoswapthem.
Andsowerepeatthatprocessagainandagain, making a SWAT, makingthis a lot, makingtheslop.
Andweonlyneedtosort n minusoneelementsintotheircorrectplace.
Becauseifyouhaveanarrayofanelementsand n minusoneofthemareintherightplace, thenthelastelementmustalsobeintherightplacebecausethere's nowhereelseforittobe.
Andtherewas a visualdemonstrationofthisshowninlecturewhereactualpeoplewerestandinguphereandtheywereswitchingplacesinordertofigureouthowtogetintotherightorder.
Sothatmightbe a helpfulthingtogobackandlookatjusttofamiliarizeyourselfwithbubblesort.
Butyes, itwasmoreefficient, andwe'llgettothatin a moment.
Butwithbubblesortspecifically, therewas a waywecouldmakeitmoreefficient.
Use a wildlyYeah, andtheideaherewaswherewedon't alwaysneedtorepeatandminusonetimesbecauseassoonaswegothroughtheelementspairbypairbypair, assoonaswegothroughalltheelementsandwedon't swapanything, wecaneffectivelystoprunningthealgorithm.