quiz2
DESCRIPTION
tldrTRANSCRIPT
-
5/1/2015 Coursera
https://class.coursera.org/algo2004/quiz/feedback?submission_id=102012 1/5
HelpCenterFeedbackProblemSet#2
YousubmittedthisquizonThu30Apr20158:53PMPDT.Yougotascoreof4.00outof5.00.Youcanattemptagain,ifyou'dlike.
Question1Supposewearegivenadirectedgraph inwhicheveryedgehasadistinctpositive
edgeweight.Adirectedgraphisacyclicifithasnodirectedcycle.Supposethatwewantto
computethemaximumweightacyclicsubgraphof (wheretheweightofasubgraphisthesum
ofitsedges'weights).Assumethat isweaklyconnected,meaningthatthereisnocutwithno
edgescrossingitineitherdirection.
HereisananalogofPrim'salgorithmfordirectedgraphs.Startfromanarbitraryvertex ,
initialize and .While ,findthemaximumweightedge withone
endpointin andoneendpointin .Addthisedgeto ,andaddtheappropriateendpoint
to .
HereisananalogofKruskal'salgorithm.Sorttheedgesfromhighesttolowestweight.Initialize
.Scanthroughtheedgesateachiteration,addthecurrentedge to ifandonlyifit
doesnotcreateadirectedcycle.Whichofthefollowingistrue?
YourAnswer Score Explanation
Bothalgorithmsalwayscomputeamaximumweightacyclicsubgraph.
Bothalgorithmsmightfailtocomputeamaximumweightacyclicsubgraph.
OnlythemodificationofPrim'salgorithmalwayscomputesa
0.00 ThemodificationofPrim'salgorithmoutputsasubgraphwith edges,where isthenumberofvertices.Doesthemaximumweightacyclicsubgraph
/
\/^ 12
%
* *
-
5/1/2015 Coursera
https://class.coursera.org/algo2004/quiz/feedback?submission_id=102012 2/5
maximumweightacyclicsubgraph.
alwayshavethisproperty?
OnlythemodificationofKruskal'salgorithmalwayscomputesamaximumweightacyclicsubgraph.
Total 0.00/1.00
Question2Consideraconnectedundirectedgraph withedgecoststhatarenotnecessarilydistinct.
Supposewereplaceeachedgecost by callthisnewgraph .Considerrunningeither
Kruskal'sorPrim'sminimumspanningtreealgorithmon ,withtiesbetweenedgecosts
brokenarbitrarily,andpossiblydifferently,ineachalgorithm.Whichofthefollowingistrue?
YourAnswer Score Explanation
Bothalgorithmscomputethesamemaximumcostspanningtreeof .
Prim'salgorithmcomputesamaximumcostspanningtreeof butKruskal'salgorithmmightnot.
Kruskal'salgorithmcomputesamaximumcostspanningtreeof butPrim'salgorithmmightnot.
Bothalgorithmscomputeamaximumcostspanningtreeof ,buttheymightcomputedifferentones.
1.00 Differenttiebreakingrulesgenerallyyielddifferentspanningtrees.
Total 1.00/1.00
!
!
-
5/1/2015 Coursera
https://class.coursera.org/algo2004/quiz/feedback?submission_id=102012 3/5
Question3Considerthefollowingalgorithmthatattemptstocomputeaminimumspanningtreeofa
connectedundirectedgraph withdistinctedgecosts.First,sorttheedgesindecreasingcost
order(i.e.,theoppositeofKruskal'salgorithm).Initialize tobealledgesof .Scanthrough
theedges(inthesortedorder),andremovethecurrentedgefrom ifandonlyifitliesona
cycleof .
Whichofthefollowingstatementsistrue?
YourAnswer
Score Explanation
Thealgorithmalwaysoutputsaminimumspanningtree.
1.00 Duringtheiterationinwhichanedgeisremoved,itwasonacycleof .Bythesortedordering,itmustbethemaximumcost
edgeof .Byanexchangeargument,itcannotbeamemberofanyminimumspanningtree.SinceeveryedgedeletedbythealgorithmbelongstonoMST,anditsoutputisaspanningtree(nocyclesbyconstruction,connectedbytheLonelyCutCorollary),itsoutputmustbethe(unique)MST.
Thealgorithmalwaysoutputsaspanningtree,butitmightnotbeaminimumcostspanningtree.
Theoutputofthealgorithmwillneverhaveacycle,butitmightnotbe
-
5/1/2015 Coursera
https://class.coursera.org/algo2004/quiz/feedback?submission_id=102012 4/5
connected.
Theoutputofthealgorithmwillalwaysbeconnected,butitmighthavecycles.
Total 1.00/1.00
Question4Consideranalphabetwithfiveletters, ,andsupposeweknowthefrequencies
, , , ,and .Whatistheexpectednumberof
bitsusedbyHuffman'scodingschemetoencodea1000letterdocument?
YourAnswer Score Explanation
2400
2230 1.00 Forexample, , , , , .
3000
3450
Total 1.00/1.00
Question5WhichofthefollowingstatementsholdsforHuffman'scodingscheme?
\ !^
"
"
"
"
"
!
!
-
5/1/2015 Coursera
https://class.coursera.org/algo2004/quiz/feedback?submission_id=102012 5/5
YourAnswer Score Explanation
Ifaletter'sfrequencyisatleast ,thentheletterwillcertainlybecodedwithonlyonebit.
Aletterwithfrequencyatleastmightgetencodedwithtwoormorebits.
Ifthemostfrequentletterhasfrequencylessthan
,thenallletterswillbecodedwithatleasttwobits.
1.00 Suchaletterwillendureamergeinatleasttwoiterations:thelastone(whichinvolvesallletters),andatleastonepreviousiteration.Inthepenultimateiteration,iftheletterhasnotyetenduredamerge,atleastoneofthetwootherremainingsubtreeshascumulativefrequencyatleast ,sotheletterwillgetmergedinthisiteration.
Ifthemostfrequentletterhasfrequencylessthan ,thenallletterswillbecodedwithmorethanonebit.
Total 1.00/1.00