You are on page 1of 14

Weiss4thEditionSolutionstoExercises (USVersion)

Chapter9Randomization
9.1KeyConceptsandHowToTeachThem ThisprobablywouldbeanappendixchapterexceptthatIwantedtodiscusspermutationgeneration,the primalitytestingalgorithm,andrandomizedalgorithmsingeneral.Ifyoudontwanttodothat,youcanskip thischapter. Therearethreebasictopics: linearcongruentialgenerators permutationgeneration randomizedalgorithms

9.1.1LinearCongruentialGenerators Youcanbeginwithadiscussionofrandomnumbersandexplainwhywemightneedtogeneratethem.Move ontoexplainthatrandomnumberssatisfycertainstatisticalproperties,andshowthatsomesequencesare notveryrandom. Youcangiveasmallexampleofthelinearcongruentialgenerator.Iftheaudienceismathematically sophisticated,youcangetintothenittygritty.Mostlikely,youwilljustwanttoshowthefinalcomputation anddiscusshowtheRandomclassworks. Thediscussiononnonuniformgeneratorsispresentmostlyforreference.Iwouldnotexpectittobecovered inaCS2class.Remember,thiscouldhavebeenanappendixifnotforthenexttwotopics. 9.1.2PermutationGeneration Thisisaniftyalgorithmthatisworthcovering,especiallyifyouassignaprogramtocomparevarioussorting algorithms.Line11issubtleandyoumaywanttodiscussit.Alternatively,youmayjusttellyourstudentsto usetheroutinewithoutunderstandingthedetails. 9.1.3RandomizedAlgorithms Randomizedalgorithmsarebecomingverypopular.Ifyoudiscussdynamicprogrammingandbacktracking duringthecourse,youwillalsowanttotalkaboutrandomizedalgorithms.Themathmaybealittle overwhelming,buttheprincipleisnot.Bytheway,Ireallydoflipthecoininclass.Youshoulddoit;the studentsloveit.Alwaysletthestudentschoose.Ialsodoitrightbeforethefinal:threeconsecutivecallsand thefinalisoff. Studentstendtothinkthatanyalgorithmthatmightmakeanerrorisunacceptable.Counterthatbyarguing thattheprobabilityofanerrorismuchsmallerthanotherphenomena,suchasapowersurgeorhardware error. 9.2SolutionstoExercises INSHORT 9.1 48271,182605794,1291394886,1914720637,2078669041,407355683,1105902161,854716505, 564586691,1596680831. 9.2 IfA=2,thenalthough25601(mod561),22801(mod561)provesthat561isnotprime.IfA=3then 3560375(mod561),whichprovesthat561isnotprime.A=4doesnotfoolthealgorithm;aswesaw above,41401(mod561).HoweverA=5isafalsewitness:515(mod561),5225(mod561),5464 (mod561),58169(mod561),516511(mod561),517311(mod561),534229(mod561),53523 (mod561),570529(mod561),5140463(mod561),528067(mod561),55601(mod561).

Page1of1

9.3 9.4

Theexpectednumberofwinnersis3andsatisfiesaPoissondistribution.Theprobabilityofexactly0 winnersise3=0.0498.Theprobabilityofexactly1winneris3e3=0.149. Ifseedis0,thenallfuturevaluesofseedwillalsobe0.

INTHEORY 9.5 TheproofofcorrectnesscanbefoundinthepaperbyParkandMillerorinmytextbookData StructuresandAlgorithmAnalysisinJava. 9.6 Weonlyhavetoshowthatthereisasequenceofswapsintheroutinethatcorrespondstothe generationofanypermutation.Thisiseasilyseeninductively:ifNisinpositioni,thenthelastswap wasbetweenpositioniandN1.WeworkthislogicbackwardsfromNto1,andconcludeinductively thateverypermutationcanbegenerated. Flipthecoinstwice,numbertheoutcomes.Ifbothcoinsareidentical,reflipbothcoinsuntiltheyare not.Ifthelatterflipisheadsgeneratea0,otherwisegeneratea1.

9.7

INPRACTICE 9.8 9.9 9.10 9.11 9.12

9.3ExamQuestions 9.1 1000randomintegersaregeneratedrandomlywithauniformdistributionovertherange1to1000 inclusive.Whichofthefollowingwouldindicateapoorgenerator? a. 1 b. logN c. N d. NlogN e. noneoftheabove 9.2 Theseedofalinearcongruentialgeneratoris a. alwayszero b. occasionallyzero,dependingonotherrandomevents c. theinitialvalue d. themultiplier e. theperiodofthegenerator Thenumberofwinninglotteryticketssatisfieswhichdistribution? a. Gaussian b. negativeexponential c. normal d. Poisson e. uniform Approximatelyhowmanyrandomnumbersareusedinthepermutationgenerationalgorithm? a. 1 b. logN c. N d. NlogN e. noneoftheabove Page2of2

9.3

9.4

9.5

Whichofthefollowingisabadcaseforrandomizedquickselect? a. anyinputwithK=1 b. reverseorderedinput c. sortedinput d. therearenobadinputs e. noneoftheabove Iftherandomizedprimalitytestingalgorithm(withoneiteration)declaresthatPisprimeandC composite,thenwhichofthefollowingismostaccurate? a. Thereisatmosta25%chancethatPhasbeendeclaredprimefalselyandthereisatmosta25% chancethatChasbeendeclaredcompositefalsely b. Pisprimewith100%certaintybutthereisatmosta25%chancethatChasbeendeclared compositefalsely c. Thereisatmosta25%chancethatPhasbeendeclaredprimefalsely,butCiscompositewithat least100%certainty d. Pisprimewith100%certaintyandCiscompositewith100%certaintyalloftheabove statementsarefactuallyincorrect

9.6

e. alloftheabovestatementsarefactuallyincorrect
9.7 Letx1,x2,beasequenceofrandomnumbersgeneratedbasedonuniformdistributionintherange 0..19.Whichof(a)(c)isfalse? a. Eachnumberintherange0..19isequallylikelytoappearatanypositioninthesequence. b. y1,y2,.....,whereyi=2xiisalsoasequenceofrandomnumberswithuniformdistributioninthe range0..38. c. c.y1,y2,.....,whereyi=ximod15isalsoasequenceofrandomnumberswithuniformdistribution intherange0..14. d. Twofromtheabovearefalse e. Allof(a)(c)aretrue Asequenceofrandomnumbersisgeneratedintherange0..30usingthefollowinggenerators. Whichoneofthefollowingbestapproximatesauniformdistribution? a. (Currenttimeinmicroseconds)mod31 b. (Currenttimeinmilliseconds)mod31 c. Rolladiceandmultiplytheresultby5 d. alloftheaboveareequallygood e. noneoftheaboveisagoodgenerator

9.8

AnswerstoExamQuestions 1. D 2. C 3. D 4. C 5. D 6. C 7. D 8. A

Page3of3

Chapter10FunandGames
10.1KeyConceptsandHowToTeachThem Thischaptercontainstwocasestudies.Thefirstillustratesauseofthebinarysearch;theseconddescribes gameplayingandusesabacktrackingalgorithmandahashtable.Thechaptertitlereferstotheparticular applications:studentslikeplayinggameswiththecomputer,sotheyrelatewelltothismaterial. 10.1.1WordSearchPuzzle First,describethebasicproblemandexaminethesimplealgorithm.Thenshowhowthebinarysearchcanbe used,andfinallydescribetheprefixtestimprovement.Thecodehasseveralpointsworthexamining: Thedatafileischeckedtomakesureitissorted.Othererrorchecksareperformed,andalthoughsomeare omittedforbrevity,itisimportantforstudentstounderstandthaterrorcheckingisimportant. ThesolvePuzzleroutinecallssolveDirectioneighttimes.Emphasizethatthismakesthingssimpler. Somestudentswilltrytoarguethatthereisalotofoverheadincurredbyeightmethodcalls,andthe repeatedaddingofzeroand+/1andthatthetestsatline1416inFigure10.8areexcessive(i.e.ifwewrote 8versionsofsolveDirection,wedhavelesstesting).Itsnottrue,andiftheydontagree,maybeitwould beagoodassignment. 10.1.2Tictactoe Thegeneralminimaxstrategyshouldbediscussedfirst.Next,illustratealphabetapruning.Thistakessome gettingusedtoforthestudents;inparticularitishardforthemtoseehowalphaandbetachangeduringthe recursion.Viewalphaandbetaasformingawindowthatshrinksastherecursivecallsdescend. Thecodeisnottoogreat,butitdoesfitinapage. Transpositiontablesillustratehowhashtablesareusedtoimplementadictionary.Thisisthefirstexampleof defininganobjectthatisinsertedintoadatastructure.Positionispackagefriendly,indicatingthatitisa throwawayobject.Noticethatwedefineequalsandprovideahashfunction. Ifyouhavethetimeandcansetupgroupprojects,agameplayingprogramisideal.Itischallenging,requires teamwork,andcanbegradedbyrunningatournament(A+forthewinner,Afortherunnerup,etc.). 10.2SolutionstoExercises INSHORT 10.1 Nocheckisperformedtoseeifalineistoolong.Nocheckismadetomakesurethatthenumberof rowsissufficientlysmall.Nochecksareperformedtomakesurethecharactersareletters. 10.2 (a)H2CandH2DarerefutationsbecauseadrawhasalreadybeenestablishedbyC1.(b)Thepositionis adraw.

INTHEORY 10.3 Leta[i]bethesmallestentryinathatstoresaprefixofx.Sincealllargerpositionsstorevalues greaterthanx,a[mid]>xformid>=i.Thusthelargestvaluelowcanassumeisi;furthermoreall smallerpositionsaregreaterthanx.Thus,whenthesearchisnarrowedtooneposition,itmustbe narrowedtolow=mid,atwhichpointaprefixtestcanbeperformed. 10.4 (a)Therunningtimedoubles.(b)Therunningtimequadruples.

INPRACTICE 10.5 Astheanalysisinthetextsuggests,forlargedictionaries,thesequentialsearchwilltakesignificantly longerthanthebinarysearch. 10.6 Theabsenceoftheprefixtestwillaffectperformance,butnotassignificantlyasifasequentialsearch wasusedinsteadofabinarysearch. Page4of4

10.7 10.8 10.9 10.10

Thedifferenceintheperformanceisnotverysignificantsincethenumberofentriesstoredare roughly300400.

10.3ExamQuestions 10.1 Supposethedictionaryisrandomlyordered.Asymptotically(thatis,intermsofalikelyBigOh runningtime),whichofthefollowingalternativesisthefastestifweassumethatnowordsarelonger thantencharacters? a. Sortthedictionary,andthenusethealgorithminthetext b. Sortthedictionary,butthenuseinterpolationsearch c. Placethedictionaryitemsinabinarysearchtree;theprefixtestmustbeperformedexplicitly d. Placethedictionaryitemsinahashtable;theprefixtestmustbeperformedexplicitly e. Useasequentialsearchofthedictionary 10.2 Whichofthefollowingistrueaboutthebacktrackingalgorithmwhenimplementedwithalphabeta pruningandatranspositiontable? a. Allterminalnodesmustbeprocessedtoguaranteeoptimalplay b. Allrecursivecallsmustleadtoeitheraterminalnode,astoredposition,orapruningto guaranteeoptimalplay c. Evenifallterminalnodesarereached,playmightnotbeoptimal d. Evenifallrecursivecallsleadtoeitheraterminalnode,astoredposition,orapruning,play mightnotbeoptimal e. Ifcomputingpowerisunlimited,thecomputerwillalwaysfindawinforthefirstplayer IntermsofD,whichisthenumberoflevelsoflookahead(orthedepthofthesearch),whichofthe following best describes the running time of the alpha-beta pruning algorithm for most games? a. exponential b. linear c. logarithmic d. quadratic e. noneoftheabove Whichofthefollowingstatementsaboutalphabetapruningistrue? a. itcomputesexactlytheanswerthatwouldbecomputedwithoutalphabetapruning b. itappliestoallrecursivecalls c. itisusedtorecordpreviouslyvisitedpositions d. exactlytwooftheabovestatementsaretrue e. allof(a),(b),and(c)aretrue Atsomepoint,alpha = 0.0andbeta = 10.0.Apossiblemoveevaluatesto6.0.Whichofthe followingistrue: a. alphaischangedto6.0ifweareevaluatingamoveforthecomputer b. alphaischangedto6.0ifweareevaluatingamoveforthehuman c. betaischangedto6.0ifweareevaluatingamoveforthecomputer d. betaischangedto6.0ifweareevaluatingamoveforthehuman e. Neitheralphanorbetaischanged WeneedtodeterminewhetherallwordsinlistAofMwordsarepresentinanotherlistBofNwords. Assumethatwordscanbeoflength1tok.Considerthefollowingtwoalgorithms:InAlgorithm1,for eachwordinA,scanBtofindtheword.InAlgorithm2,wefirstdecomposeBintoklists,L1,...,Lk,

10.3

10.4

10.5

10.6

Page5of5

whereLicontainswordsoflengthi.ForeachwordwinA,searchforwinlistLx,wherexisthelength ofw.Whichof(a)(c)isfalse? a. TherunningtimeofAlgorithm1isO(NMk). b. Algorithm1islikelytobebetterthan2ifM=1. c. Algorithm2islikelytobebetterthan1ifkislarge. d. alloftheabovearetrue e. noneoftheaboveistrue 10.7 Transpositiontablesareusedinoptimizationofgames.Whichof(a)(d)isfalse? a. Atranspositiontablestorespreviouslyevaluatedpositions. b. Useoftranspositiontablesmayrequiremorememory. c. Useoftranspositiontablesresultsinlessoverallexecutiontime. d. Positionsintranspositiontablesmustbestoredinorderedmanner. e. alloftheabovearetrue

AnswerstoExamQuestions 1. D 2. B 3. A 4. D 5. D 6. D 7. D

Page6of6

Chapter11StacksandCompilers
11.1KeyConceptsandHowToTeachThem Myalltimefavoriteexampleisprobablythebalancedsymbolprogram.Itiseasytodescribethealgorithm, andbecauseofsomeweakerrorreportingbysomecompilers,itisextremelyuseful.Theinfixtopostfix conversionalgorithmisanotherfavorite,thoughitislessintuitiveforthestudents.Thesecasestudiesare excellentforillustratingthebasicsofhowstacksareused,andtheinfixconversionprogramhastwostacksof differenttypes,thusprovidingapowerfulexampleofthepowerofgenericprogramming. 11.1.1BalancedSymbolChecker Thealgorithmissimpleandthestudentsgenerallyhavenotroublewithit.Errorrecoveryismuchmore challenging,andyoucanaskthestudentstotryit,butthisisnotsoeasy. Alsointroducedinthissectionisthestatemachine.Youcanshowfinitestatemachines,butIhavenotdoneit inmypresentationbecausethereareonlythreestates.Gothroughthestatemachinealgorithmtwice, becausemyexperienceisthatstudentsdontreallyseeitthefirsttime. ThisisoneofthefewplacesinwhichIusethewordspreconditionandpostcondition.Ihavetriednotto overcomment,butparsingisaclearcasewhereyouneedtoknowwhatyouvereadbeforecominginand whatwillhavebeenreadwhenyouaredone. 11.1.2InfixtoPostfixConversion Beginbyexplaininghowapostfixmachineworks.Studentsgenerallyhavenoproblemwiththis.Iliketo begintheinfixalgorithmbygivingsomeintuitionaboutwhythestackisused;thesearethefirstfew paragraphsofSection11.2.2.WecanthenlogicallyanalyzethesituationandcomeupwiththerulesonPage 385.Youwillwanttodoseveralexamplesofthealgorithm. Theimplementationhasseveralinterestingfacetsincludingthetwotypesofstacks.Pointouthowmuch errorcheckingisbeingperformed(theexercisesindicatethatsomechecksarestillmissing).Explainhowthe precedencetableisbeingused.Thesekindsoftablesareimportantdesigntoolsbecausetheymakeiteasyto addnewcases. Thereareseverallogicalextensionsthatareproposedintheprogrammingprojectssection.Pickone. 11.2SolutionsToExercises INSHORT 11.1 (a)Anextraneous}isdetected.(b)The}isdetectedtonotmatch(.(c)Threemessagesareprinted toindicatethat[isunmatched.(d)The)isextraneousandthe(isunmatched.(e)The)doesnot matchthe[andthe]isextraneous. 11.2 (a)1 2 + 3 4 ^ -;(b)1 2 ^ 3 4 * -;(c)1 2 3 * + 4 5 ^ - 6 +;(d)1 2 + 3 * 4 5 6 - ^ -

Page7of7

11.3

(a)SeeFigure11.1(b)SeeFigure11.2;t1throught9aretemporaries.(c)SeeFigure11.3.
Infix:a+b^c*d^e^fgh/(i+j)

Postfix:abc^def^^*+ghij+/ Figure11.1InfixtopostfixforExercise11.3

Page8of8

Postfixexpression:abc^def^^*+ghij+/

Figure11.2PostfixmachinestepsforExercise11.3

Page9of9

Figure11.3ExpressiontreeforExercise11.3(c)

INTHEORY 11.4 11.5 Unaryminusandbinaryminusareconsidereddifferentsymbols.Theunaryminusoperatorpops onlyonesymbolfromthepostfixstackinsteadoftwoandhasprecedencehigherthanthebinary minusoperator.Itisrighttoleftassociative.Torecognizeaunaryminusoperator,wemust rememberifthelasttokenmatchedwasanoperator;ifso,wehaveaunaryminusoperator; otherwisewehaveabinaryminusoperator.

INPRACTICE 11.6 Themaindifficultyisthatthescanningroutinemustbemodifiedtorecognizethe**token.This involvesusinglookaheadwhena*isseen,andpushingbackacharacterifthenextcharacterisnot thesecond*. 11.7 (a)7;(b)Dontallowanoperandtobeacceptedunlesstherehasbeenanoperatorpriortoit.

11.3ExamQuestions 11.1 Theinfixexpression1^23*4isconvertedtopostfix.Whatistheorderinwhichoperatorsare poppedfromthestackintheinfixtopostfixalgorithm? a. ^* b. *^ c. *^ d. ^* e. noneoftheabove 11.2 Whichofthefollowingtypesofexpressionsrequiresknowledgeofprecedencerules? a. infixandpostfix b. infixonly c. postfixonly d. neitherinfixnorpostfix

Page10of10

11.3

Whatpostfixexpressiondoestheexpressiontreebelowrepresent?

a. b. c. d. e. 11.4

a + b * c - d ( a + b ) * ( c - d ) a b + c d - * a b c d + - * noneoftheabove

Whichofthefollowingrepresentsaninfixexpressionfollowedbythepostfixequivalent? a. a + b - canda b c - + b. a + b * canda b c * + c. a + b * canda b c +* d. a + b * canda b + c * e. morethanoneoftheabove Forwhich(inputsymbol,thesymbolatthetopofthestack)pairisthesymbolatthetopofthestack notpopped? a. (+, *) b. (+, +) c. (*, +) d. (*, *) e. morethanoneoftheabove Whichoneof(a)(d)doesnotindicateanerrorwhencheckingforbalancedparenthesis? a. Intheend,thestackcontainsoneleftparenthesis. b. Intheend,thestackcontainsonerightparenthesis. c. Intheend,stackisempty d. Thenextsymbolisrightparenthesisandthestackisempty. e. alloftheaboveindicateanerror Whichof(a)(d)isfalse? a. Apostfixexpressiondoesnotrequireparenthesistospecifyevaluationorder b. Foreveryinfixexpression,thereexistsanequivalentpostfixexpression. c. Foreverypostfixexpression,thereexistsanequivalentinfixexpression. d. Evaluationofapostfixexpressioncanbedoneinlineartime. e. alloftheabovearetrue

11.5

11.6

11.7

AnswerstoExamQuestions 1. D 2. B 3. C 4. B 5. A 6. C 7. E

Page11of11

Chapter12Utilities
12.1KeyConceptsandHowToTeachThem Huffmansalgorithmisaclassicandisworthdiscussing.If,however,youareconcernedwithseeingcode thatusesthedatastructures,thenstickwiththecrossreferencegenerator. 12.1.1HuffmansAlgorithm Themotivationforthishasbecomemucheasierwiththewidespreaduseofhomecomputers.Many studentswillhaveusedfilecompressionontheirhomesystem.Mostmodemshavecompressionbuilt in.ManyfilesthatareobtainedfromtheInternetarecompressed. ThestudentsdonotseemtohavedifficultywithHuffmansalgorithm.Ifyouassignitforaprogramming project,youmaywanttoprovidethestudentswithaBitStreamclass.Alternatively,thisisagreatexcuseto havethestudentswriteaBitStreamclass. 12.1.2CrossreferenceGenerator Thisisanothereasymotivation,sincestudentsseethepracticality.Thecodeillustratesanotherstate machine.Thiscodeisnotasbadasitlooks,andeverylineofcodedoessomethingveryidentifiable. IliketolayoutalloftheabstractionswhenIfirstdescribewhatishappening.Buttowardstheend,Iliketo showthestudentswhatwouldbegoingoninalanguagelikeCifthingswerenotprivate.Itistrulyscary, becausetherearereferenceseverywhere,particularlyifweusethelinkedlistimplementationofthequeue. Oncethestudentsseethis,thenwhentheycangetthecrossreferencegeneratortowork,theyaresoldon theideaofencapsulationandinformationhidingforlife. 12.2SolutionsToExercises INSHORT 12.1 AHuffmantreeisshownbelow.

Figure12.1HuffmantreeforExercise12.1

Page12of12

12.2 12.3

OnUNIX,usingcompress,compressionseemsworthwhileformoderatelylargetextfilessuchas50K ormore.ForlargePostscriptfilesorFramefiles,thesavingscanbe75%ormore. Becauseonlyleavesimplyacode,Huffmansalgorithmtendstonoticemissingbitsquickly,andalso tendstoresynchronizequickly.Thusafewcharactersmaybelost,buttherestofthetransmissionis likelytobeintelligible.

INTHEORY 12.4 (a)Followsfromthetextdiscussion;(b)otherwise,wecouldswapadeepandmoreshallownode andlowerthecostofthetree;(c)true,sincethecostofthetreedependsonthedepthandfrequency ofanode. 12.5 (a)A2bitcodeisgeneratedifasymbolisinvolvedinthelastmerge.Forthistooccur,itmusthave frequencygreaterthan1/3(sothatwhenthreesymbolsremain,itisnotoneofthesmallesttwo trees).However,itisstillpossiblethatevenwithfrequencylessthan1/2,anodewillhavemorethan atwobitcode.(b)LetFNbetheNthFibonaccinumber.Ifthecharacterdistributionis1,1,1,2,3,5,8, 13,...,thenthefirstcharacterwillhavealongcode.Specifically,wecanconstructaHuffmantreeof lengthNifthetotalcharacterfrequencyisFN.Thisisseentobeaworstcasescenario,sofora20bit codetooccur,thefrequencyofacharactermustbeatmost1/F20(orabout.0001),andprobably somewhatless. MaintaintwoqueuesQ1andQ2.Q1willstoresinglenodetreesinsortedorder,andQ2willstore multinodetreesinsortedorder.PlacetheinitialsinglenodetreeintoQ1,enqueueingthesmallest weighttreefirst.InitiallyQ2isempty.ExaminethefirsttwoentriesofeachofQ1andQ2,and dequeuethetwosmallest.(Thisrequiresaneasilyimplementedextensionofthequeueclass).Merge thetreeandplacetheresultattheendofQ2.ContinuethisstepuntilQ1isemptyandthereisonly onetreeleftinQ2. Inanycodingscheme,theoutputfilemustcontaintheencodingtableandthenthecompressedfile.If theoriginalfilecontainsallsymbolswiththesamefrequency,therewillnotbeanysavingsinterms ofstorage.Theencodingtablewillbeanextraoverhead.

12.6

12.7

INPRACTICE 12.8 12.9 12.10 12.11 12.12 12.13

12.3ExamQuestions 12.1 Whichofthefollowingmustbetrueaboutfilecompressioningeneral? a. Allfilescanbecompressed b. Foranyfile,theremustbesomecodesthatarelongerthanothers c. Thecodemustbeaprefixcode d. alloftheabove e. noneof(a),(b),and(c) 12.2 12.2.WhichofthefollowingalgorithmtypesclassifiesHuffmansalgorithm? a. backtrackingalgorithm b. divideandconqueralgorithm c. dynamicprogrammingalgorithm Page13of13

d. e. 12.3

greedyalgorithm noneoftheabove

12.3.WhichofthefollowingcharacterizesaHuffmancodingtree? a. allitemsarestoredattheleaves b. nonodeshaveonechild c. thetreeisbalanced d. (a)and(b)only e. allthreeof(a),(b),and(c) 12.4.Whichofthefollowingisnotanapplicationofcrossreferencegeneration? a. indexingatextbook b. listingalloccurrencesofeachmisspelledwordinadocument c. listingallusesofeachobjectinaprogram d. transmittinglargefilesoveraphoneline e. alloftheaboveareapplicationsofacrossreferencegenerator Whichofthefollowingisavalidprefixcodeforafilecontainingonlythecharacters,a,b,candd? a. a = 1, b = 0, c = 01, d = 10 b. a = 10, b = 01, c = 00, d = 11 c. a =1, b = 01, c = 101, d = 0001 d. a = 1, b = 10, c = 100, d = 1000 e. Allofthesearevalid. Whichoneof(a)(d)isfalseforHuffmancoding? a. Huffmancodingresultsinafulltree b. Nodesatgreaterdepthinthetreehavelargercode. c. Huffmansalgorithmconstructsanoptimalprefixcode. d. Forafilecontainingonlykcharacters,Huffmancodingcanresultinacodeoflengthk. e. alloftheabovearetrue

12.4

12.5

12.6

AnswerstoExamQuestions 1. E 2. D 3. D 4. D 5. B 6. E

Page14of14

You might also like