/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Q2E Suppose we want to find the mini... [FREE SOLUTION] | 91影视

91影视

Suppose we want to find the minimum spanning tree of the following graph.

(a) Run Prim鈥檚 algorithm; whenever there is a choice of nodes, always use alphabetic ordering (e.g., start from node A). Draw a table showing the intermediate values of the cost array.

(b) Run Kruskal鈥檚 algorithm on the same graph. Show how the disjoint-sets data structure looks at every intermediate stage (including the structure of the directed trees), assuming path compression is used.

Short Answer

Expert verified

a). The cost of the minimum spanning tree by using prim鈥檚 algorithm is 12.

b). the cost of the minimum spanning tree by using Kruskal鈥檚 algorithm is 12.

Step by step solution

01

 Introduction of Minimum spanning tree:

The minimum spanning tree is an edge-weighted graph whose weight is not more than the weight of any other spanning tree.Prim鈥檚 algorithm is based on same graph which based on set of data structure looks at every intermediate state allowing different kind of structure of directed trees.

Prim鈥檚 algorithm is based on same graph which based on set of data structure looks at every intermediate state allowing different kind of structure of directed trees.

02

Step 2: Determine the minimum spanning tree using Prim’s algorithm:

Procedure prim ( G,w )

Input: The graph G = (V,E) with edge weights.

Output: Minimum spanning tree.

Step1: for all UoV:

cost(u)=0prev(u)=nilpickanyfirstnodeU0costU0=0

Step2: H = makequeue (V) (priority queue with the help of the cost-value as keys)

Step3: whileH is not empty:

Step4: v = deletemin (H)

foreachv,zoEcheckifcost(z)>w(v,z):cost(z)>w(v,z)prev(z0=vdecreasekey(H,z)

鈥 Using the cost values, create a priority queue.

鈥 Make sure the queue isn't empty.

Assign and remove the smallest node possible.

The for loop runs until the edge " E " is reached.

鈥 Determine if the node's cost exceeds that of the minimal neighbour node.

鈥 Include the cost of the minimal neighbour nodes.

鈥 Assign the preceding node to the smallest neighbour node.

鈥 Reduce the key value.

鈥 Once all of the vertex in the MST are connected and there are N - 1edges, stop.

Execute this prim's algorithm on the given graph UoV.

鈥 Initializes the cost node '' cost (u) '' as infinite and previous node '' prev (u) '' as NIL and prefer the initial node of U0=A.

03

Run Prim’s algorithm for finding minimum spanning tree.

a).

Refer to the network in textbook question 5.2 and assign " v = A " to the lowest node from priority queue "H". There are (A,B), (A,F), and (A,E) edges for " A " vertex. The prices for

, and are all the same. And find out the vertices with the lowest cost. The cost of is the cheapest. Assign the cost value to " ," .the previous value to " ," and the key value to "decrement." After then, the structure is as follows:

Assign " v = B " to the lowest node on prioritized queues " H ."

There really are (B,F) , (B,C), and (B,G) edges for the " B " vertex. The prices for (B,F) = 6, (B,C) = 2, and (B,G) = 6 are all the same. Look for the vertices (B,F) , (B,C), and (B,D) with the lowest cost (B, G) The cost of (B,C) = 2 is the cheapest. As a result, double the current cost by the prior value.

costz=1+2=3

Assign the previous value as 鈥 prev (z) = 3 鈥 and decrement the key value. and the minimum node from 鈥 H 鈥 as 鈥 v = C 鈥.For 鈥C鈥 vertex, there are (C,D) and (C, G) edges. The cost for (C, D) = 3 and (C, G) = 2. Check for the minimum cost among the vertices The cost of is minimum. So, add the current cost with previous value.

Assign the previous value as 鈥 鈥 and decrement the key value. Assign the minimum node from For 鈥鈥 vertex, there are edges, The cost for Check for the minimum cost among the vertices Take the cost of is minimum in priority manner.So, add the current cost with previous value.

After that assign the previous value as 鈥 鈥 and decrement the key value. Now, take the cost of is minimum in priority manner. So, add the current cost with previous value.

cos(z)=6+1=7

Assign the previous value as 鈥 prev (z) =7鈥 and decrement the key value. Now, take the cost of (G,H) = 1 is minimum in priority manner. So, add the current cost with previous value.

cos(z)=7+1=8

Assign the previous value as 鈥 prev(z)=8 鈥 and decrement the key value. Assign the minimum node from "H" as "v = D" For "D" vertex, there are (D,C) and (D,H) edges. So, ignore this vertex and there is no change in the structure. Again, assign the minimum node from "H" is "v = F" For 鈥 F 鈥 vertex, there are (F,E) is in the tree. So, ignore this vertex and there is no change in the structure. The minimum node from "H" is "v=E" . For 鈥 E鈥 vertex, there are (E,A) is not in the tree. Check whether the minimum cost from the vertices (E,A).

The cost for E,A=4.

Take the cost of E,A=4is minimum in priority. So, add the current cost with previous value.

cosz=8+4=12

Assign the previous value as 鈥 prev(z) = 12 鈥 and decrement the key value. Assign the minimum node from "H" is "v=H" for 鈥H鈥 vertex, there are (H,D) is in the tree. So, ignore this vertex and there is no change in the structure. Then, the structure is shown below:

Thus, the minimum spanning tree using the Prim鈥檚 algorithm is shown below:

Table for cost Array:

Vertex in Graph

Edge in Graph

Cost

A

0

B

(A,B)

0+1=0

C

(B,C)

1+2=3

D

(C,G)

3+2=5

E

(G,D)

5+1=6

F

(G,F)

6+1=7

G

(G,H)

7+1=8

H

(E,A)

8+4=12

Therefore, the cost of the minimum spanning tree is 鈥 12 鈥.

04

frfgrf

b).

Kruskal鈥檚 algorithm:

Procedure Kruskal ( G,w )

Input: G = (V , E)graph with edge weights we

Output: Minimum spanning tree

Step1: for all uV

make set (u)

Step2: X = { }

Step3: Sort the edges E by weight

Step4: for all edges { u ,v } localid="1659076322808" E, in order of increasing

weight: check if find (u) localid="1659076327631" find (v):

add edge { u ,v } to X

union (u , v)

鈥 Sort the edges in order of increasing weight.

鈥 Add an edge to the MST as long as it does not form a cycle with edges added in previous passes.

鈥 Stop when all of the vertices are connected and there are N - 1 edges in the MST.

For given graph, run the Kruskal鈥檚 algorithm.

1: Call themakeset (u).

2: Initialize the values X = { }.

3: Sort the edges in the increasing order.

1:(AB),1:(D,G),1:(F,G),1:(H,G),2:(B,C),2:(B,C),2:(C,G)3:(C,D),4:(A,E),4:(D,H)5:(E,F),6:(B,F),6:(B,G),8:(A,F)

4: Loop executes over the ordered edges. For edge , (A,B), (D,G), (F,G), (H,G), (B,C), (C,G), (C,D), (A,E)(D,H), (B,F), (B,G), (A,F) Then, the structure is :

5:Finally, the minimum spanning tree is shown below:

Therefore, the cost of the minimum spanning tree is .

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 91影视!

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

Graphs with prescribed degree sequences. Given a list of n positive integers d1,d2,,dn, we want to efficiently determine whether there exists an undirected graphG=(V,E) whose nodes have degrees preciselyd1,d2,,dn . That is, if V={v1,,vn}, then the degree of vi should be exactly di. We call (d1,,dn) the degree sequence of G. This graph G should not contain self-loops (edges with both endpoints equal to the same node) or multiple edges between the same pair of nodes.

(a) Give an example of d1,d2,d3,d4 where all the di3 and d1+d2+d3+d4 is even, but for which no graph with degree sequence(d1,d2,d3,d4) exists.

(b) Suppose that d1d2d3dn and that there exists a graph G=(V,E) with degree sequence (d1,,dn). We want to show that there must exist a graph that has this degree sequence and where in addition the neighbors of v1 are v2,v3,,vdi+1 . The idea is to gradually transform G into a graph with the desired additional property.

i. Suppose the neighbors ofv1 in Gare not v2,v3,,vdi+1. Show that there exists i<jn and uV and such that {v1,vi},{u,vj}Eand {v1,vj},{u,vi}E

ii. Specify the changes you would make to G to obtain a new graph G'=(V,E') with the same degree sequence as G and where (v1,vi)E'.

iii. Now show that there must be a graph with the given degree sequence but in which v1 has neighbors v2,v3,,vdi+1.

c) Using the result from part (b), describe an algorithm that on input d1,,dn (not necessarily sorted) decides whether there exists a graph with this degree sequence. Your algorithm should run in time polynomial in n and in m=i=1ndi .

Consider the following graph.

(a) What is the cost of its minimum spanning tree?

(b) How many minimum spanning trees does it have?

(c) Suppose Kruskal鈥檚 algorithm is run on this graph. In what order are the edges added to the MST? For each edge in this sequence, give a cut that justifies its addition.

We use Huffman's algorithm to obtain an encoding of alphabet {a,b,c}with frequencies fa,fb,fc. In each of the following cases, either give an example of frequencies (fa,fb,fc)that would yield the specified code, or explain why the code cannot possibly be obtained (no matter what the frequencies are).

(a) Code:{0,10,11}

(b) Code:{0,1,00}

(c) Code:{10,01,00}

Under a Huffman encoding of symbols with frequenciesf1,f2,.....,fn , what is the longest a codeword could possibly be? Give an example set of frequencies that would produce this case.

The basic intuition behind Huffman鈥檚 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" ficili.

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

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.