quiz2

5
Help Center Feedback — Problem Set #2 You submitted this quiz on Thu 30 Apr 2015 8:53 PM PDT. You got a score of 4.00 out of 5.00. You can attempt again, if you'd like. Question 1 Suppose we are given a directed graph in which every edge has a distinct positive edge weight. A directed graph is acyclic if it has no directed cycle. Suppose that we want to compute the maximumweight acyclic subgraph of (where the weight of a subgraph is the sum of its edges' weights). Assume that is weakly connected, meaning that there is no cut with no edges crossing it in either direction. Here is an analog of Prim's algorithm for directed graphs. Start from an arbitrary vertex , initialize and . While , find the maximumweight edge with one endpoint in and one endpoint in . Add this edge to , and add the appropriate endpoint to . Here is an analog of Kruskal's algorithm. Sort the edges from highest to lowest weight. Initialize . Scan through the edges; at each iteration, add the current edge to if and only if it does not create a directed cycle. Which of the following is true? Your Answer Score Explanation Both algorithms always compute a maximumweight acyclic subgraph. Both algorithms might fail to compute a maximumweight acyclic subgraph. Only the modification of Prim's algorithm always computes a 0.00 The modification of Prim's algorithm outputs a subgraph with edges, where is the number of vertices. Does the maximumweight acyclic subgraph

Upload: pramod-srinivasan

Post on 27-Sep-2015

41 views

Category:

Documents


1 download

DESCRIPTION

tldr

TRANSCRIPT

  • 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