Give You are given a graphG=(V,E)with positive edge weights, and a minimum spanning tree T=(V,E)with respect to these weights; you may assume GandTare given as adjacency lists. Now suppose the weight of a particular edge eE'is modified fromw(e)to a new value w'(e). You wish to quickly update the minimum spanning tree T to reflect this change, without recomputing the entire tree from scratch. There are four cases. In each case give a linear-time algorithm for updating the tree.

(a) eE'and w'(e)>w(e) .

(b) role="math" localid="1658907878059" eE'and w'(e)>w(e) .

(c) role="math" localid="1658907882667" eE'and w'(e)>w(e) .

(d) role="math" localid="1658907887400" eE'and w'(e)>w(e) .

Short Answer

Expert verified

Use G and T as adjacency lists and if weight of special edge is change from old value w(e) to new value w'(e) faster update minimum spanning tree to reflect change.

Step by step solution

01

Minimum Spanning Tree:

A minimal spanning tree (MST as a minimum spanning tree) is a subgroup of something like a tree that has the shortest packets from the source to all of its vertex points. A graph G = (V,E) Some minimum spanning tree is shown, along with edge weights that are positive. T=(V,E) such as relation to all of these weights. Take a look at the clustering lists. Graph G and T are supplied. After this step suppose that a particular edge’s weight is altered from w(e) to w'(e) .

02

Update w(e) > w'(e) is answer for (a).

a).

Algorithm:

Input:

Graph: G = (V,E)

minimum spanning tree: T = (V,E)

Procedure is given as

Declare T and G as adjacency list

Declare e ,

if (e is in e )

Modify w(e)to w'=e.

Else If (e is not in [E])

Update w (e) > w'(e)

Explanation of the given equation is as follows:

Consider the minimum spanning tree when the weight of one edge eE'is decreased. Assume that e=(u,v) .Add edge e to T tree that will create a distinct cycle, that can be found applying breadth first search and not considering weights. And this will take OT=OV time. And remove the cycle's maximum weight edge OV.

In this way linear time algorithm for updating a tree when eE'and w(e) > w'(e) is given.

03

Update T with e∉E'and w'(e) < w (e) : 

(b).

Algorithm:

Input:

Graph: G = (V,E)

minimum spanning tree: T = (V,E)

Procedure is given as

Declare T and G as adjacency list

Declare e ,

if ( is in e )

Modify w(e) to w'(e) .

Else If (e is not in [E])

Making change w(e) to w'(e) .

Else If (e is not in [E])

Update w'(e)<w(e)<p=" ">

Update T with w'(e) .

End.

Explanation:

Take into account the MST while one of the edge's weights is increased, as well as the outcomes of a Kruskal method.eE. That outcome is just the same as when edge demand is higher and also the minimum value gets chosen by the algorithm. (This suggests that the edges' weights are distinct.) Whenever the tree is updated in this fashion, a linear time approach is used. eE and w(e) < w'(e) is given.

04

Prove e∉E and w'(e) < w(e) .

(c)

Algorithm:

Input:

Graph: G = (V,E)

minimum spanning tree: T = (V,E)

Procedure is given as

Declare T and G as adjacency list

Declare e ,

if ( is in e)

Update w'(e) <w (e) <p=" ">

Update Tu with w' = (e)

Update Tvwith w'(e)

end

Explanation:

Analyse how minimum spanning t until one of the edges is heavier than the other eE'. And it is increased Let e = (u,v) and just let the subtrees that were created by deleting them e be Tvand Tu. With BFS (breadth first search )(ignoring weights of edges) , It really is possible to detect whichever vertices are all in the localid="1658916013612" Tu and which are in Tv in time localid="1658917474694" OV+EAssume each node is marked with its membership.

Each edge is checked and edge e' with having one endpoint Tu and Tvhaving the other only are kept This is possible to be done in time OV . Then the complete runtime is OV+E. Whenever the tree is updated throughout this fashion, a linear time approach is used. eEand w(e) > w'(e) is given.

05

Step 5: Prove e∉E  and w'(e) >w (e)  .

(d).

Algorithm:

Input:

Graph: G = (V,E)

minimum spanning tree: T = (V,E)

Procedure is given as

Declare T and G as adjacency list

Declare e ,

wedge cost W ;

decrement

when (w - d ), new cost T'

If (e is in [E])

Update w'(e)<w(e)<p=" "style=" box-sizing-box;"></w(e)<>

Update Tu with w’(e) with T'

Update Tv with w’(e) with T'

End

Explanation:

Whenever one of the edge's weights changes, think about the MST. eE' is reduced. Assume that T is the tree, and W is the weight of the tree. Once the value of the edge gets reduced by d, their actual cost is ( W - d ). Describe the subtrees of T as Tu and Tv , when edge e is deleted. Assuming T somehow doesn't stay an MST, its edge e is required for any T' to continue an MST. But both Tu and Tv Otherwise, T may not even be basic to begin with if they weren't MSTs with each respective node sets. As a result, the weight Tv can’t be lesser ( W - d ). Whenever a tree is updated in this fashion, a linear time approach is used eE'and w(e) > w'(e) .

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question:Show how to implement the stingy algorithm for Horn formula satisfiability (Section 5.3) in time that is linear in the length of the formula (the number of occurrences of literals in it). (Hint: Use a directed graph, with one node per variable, to represent the implications.)

The following statements may or may not be correct, In each case, either prove it (if it is correct) or give a counter-example (if it isn’t correct). Always assume that the graph G=(V,E)is undirected. Do not assume that edge weights are distinct unless this is specifically stated.

  1. If a graph G has more than |V|-1edges, and there is a unique heaviest edge, then this edge cannot be part of a minimum spanning tree.
  2. If G has a cycle with a unique heaviest edge e, then e cannot be part of any MST.
  3. Let e be any edge of minimum weight in G. Then e must be part of some MST.
  4. If the lightest edge in a graph is unique, then it must be part of every MST.
  5. If e is part of some MST of G, then it must be a lightest edge across some cut of .
  6. If G has a cycle with a unique lightest edge e must be part of every MST.
  7. The shortest-path tree computed by Dijkstra’s algorithm is necessarily an MST.
  8. The shortest path between two nodes is necessarily part of some MST.
  9. Prim’s algorithm works correctly when there are negative edges.
  10. (For any r>0, define an r-path to be a path whose edges all have weight <r). If G contains an r-path from node s to t , then every MST of G must also contain an r-path from node s to node t.

The basic intuition behind Huffman’s algorithm, that frequent blocks should have short encodings and infrequent blocks should have long encodings, is also at work in English, where typical words like I, you, is, and, to, from, and so on are short, and rarely used words like velociraptor are longer.

However, words like fire!, help!, and run! are short not because they are frequent, but perhaps because time is precious in situations where they are used.

To make things theoretical, suppose we have a file composed of m different words, with frequencies f1,...,fm. Suppose also that for the ithword, the cost per bit of encoding is ci. Thus, if we find a prefix-free code where the ithword has a codeword of length Ii, then the total cost of the encoding will be localid="1659078764835" fi·ci·li.

Show how to modify Huffman’s algorithm to find the prefix-free encoding of minimum total cost.

Prove the following two properties of the Huffman encoding scheme.

(a) If some character occurs with frequency more than 25, then there is guaranteed to be a codeword of length 1 .

(b) If all characters occur with frequency less than13 , then there is guaranteed to be no codeword of length 1 .

Consider an undirected graph G=(V,E)with nonnegative edge weights role="math" localid="1658915178951" we0. Suppose that you have computed a minimum spanning tree of G, and that you have also computed shortest paths to all nodes from a particular node role="math" localid="1658915296891" sV. Now suppose each edge weight is increased by 1: the new weights are w0e=we+1.

(a) Does the minimum spanning tree change? Give an example where it changes or prove it cannot change.

(b) Do the shortest paths change? Give an example where they change or prove they cannot change.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free