Question

In: Computer Science

(1) Run Prim's algorithm and Kruskal's algorithm for the following graph: G(V, E) where V =...

(1) Run Prim's algorithm and Kruskal's algorithm for the following graph:

G(V, E)
where V = {A, B, C, D, E}
E = { {A,B}, {B,C}, {C, A}. {B, D}, {B, E}, {D, E}}
use edge weights: w({A, B} = 1), w({B, C}) = 2, w({C, A}) = 3, w({B, D}) = 4, w({B, E}) = 5, w({D, E}) = 6.

(2) Can the maximum weight edge be in every minimum spanning tree of a graph?

Solutions

Expert Solution

V = {A, B, C, D, E}
E = { {A,B}, {B,C}, {C, A}. {B, D}, {B, E}, {D, E}}
Weights = w({A, B} = 1), w({B, C}) = 2, w({C, A}) = 3, w({B, D}) = 4, w({B, E}) = 5, w({D, E}) = 6

Therefore the graph will be:

#1. Kruskal's:

In this algorithm we first sort the edges in non-decreasing order of their weights:

w({A, B} = 1),
w({B, C}) = 2,
w({C, A}) = 3,
w({B, D}) = 4,
w({B, E}) = 5,
w({D, E}) = 6

Now we draw the MST by joining vertices with minimum edge weight, making sure that no cycles are formed.

Hence we start from the minimum edge and move on:

First, let us assume that all the vertices are empty trees we will now one by one establish the connections between them using Kruskal's Algorithm forming the minimum spanning tree of the above graph.
"I will also highlight this work on the graph"

Edge {A, B} has minimum weight, which is 1, so we put this edge in tree:

Now next edge is: {B, C}) = 2

Next edge is {C, A}) = 3:
so the tree will be:

but by joining this edge we have formed a cycle, hence we have to remove this edge:
So the resulting MST will be:

Now next edge is {B, D}) = 4:

Now next edge is {B, E}) = 5:

Now the last edge which is {D, E} = 6:

Here also we see that a cycle is formed and hence we have to remove this edge, So the tree will be:

Now we have no edge left and hence this is the rsulting Minimum Spanning Tree:

This is the resulting MST formed using Kruskal's Algorithm, with total weight = 1 + 2 + 4 + 5 = 12.

Traversing from the graph:
1:

2:

3:
4:

#2 Prim's :

In this algorithm of finding Minimum Spanning Tree,
We create an empty tree,
We then start from a source node or vertex of the graph and then create a tree including that vertex only.
Then we find all the edges connected to that vertex and then find the edge with the minimum weight, and we then connect that minimum weight edge to that vertex of the tree.
We have to make sure that after connecting the new edge there must not be any cycle formed in the tree, and if a cycle is formed we remove that edge.
And we keep doing this we get the resulting minimum spanning tree.

Let's start with the vertex 'A':


Now edges containing A are:
{A, B} = 1,
{C, A} = 3
Here we see that the edge with the minimum weight is {A, B} = 1,
So we get:

Now we have 2 vertices so we find all the edges containing them:
A: {A, B} = 1, {C, A} = 3
B: {A, B} = 1, {B, C} = 2, {B, D} = 4, {B, E} = 5

The edge {A, B} = 1 is already included hence we ignore it.

From the rest of the edges, the minimum weighted is {B, C} = 2, So we include this edge:

Now we have three vertices so now again finding all edges containing them:

A: {A, B} = 1, {C, A} = 3
B: {A, B} = 1, {B, C} = 2, {B, D} = 4, {B, E} = 5
C: {B, C} = 2, {C, A} = 3


Now the minimum weighted edge out of these edges excluding those which are already included in the resulting tree, is {C, A} = 3,

But here if we include this edge we get a cycle formed which we are not allowed to have, Hence we drop this edge and move to next minimum edge which is {B, D} = 4

Now we have 4 vertices and all edges containing them are:
A: {A, B} = 1, {C, A} = 3
B: {A, B} = 1, {B, C} = 2, {B, D} = 4, {B, E} = 5
C: {B, C} = 2, {C, A} = 3
D: {B, D} = 4, {D, E} = 6

Now the minimum weighted edge out of these edges excluding those which are already included in the resulting tree, is {C, A} = 3, but we know that it will form the cycle so we drop this one, and then the next minimum edge which is not already included in the tree is {B, E} = 5,

Now we have 5 vertices so we find all edges containing them:
A: {A, B} = 1, {C, A} = 3
B: {A, B} = 1, {B, C} = 2, {B, D} = 4, {B, E} = 5
C: {B, C} = 2, {C, A} = 3
D: {B, D} = 4, {D, E} = 6
E: {B, E} = 5, {D, E} = 6

Now the minimum weighted edge out of these edges excluding those which are already included in the resulting tree, is {C, A} = 3, but we know that it will form the cycle so we drop this one, and then the next minimum edge which is not already included in the tree is {D, E} = 6,

But if we include this edge we form a cycle and hence we stop here.
There is no more edge to include.

Hence the resulting MST is:

Traversing from the graph:
1:

2:

3:
4:

#3:
Can the maximum weight edge be in every minimum spanning tree of a graph?

NO MAXIMUM WEIGHTED IS NOT NECCERILY INCLUDED IN EVERY MINIMUM SPANNING TREE.
FOR EXAMPLE, IF ALL EDGES ARE OF SAME WEIGHT WHICH IS ALSO MAXIMUM WEIGHT, AND TO FOR A MINIMUM SPANNING TREE WE MUST INCLUDE ALL THE EDGES WITH MINIMUM WEIGHT FORMING NO CYCLES, THUS WE HAVE to INCLUDE THE MAXIMUM WEIGHTED EDGE THERE.

BUT AS I SAID IT IS NOT NECCERY IN EVERY CASE.
AS IN THE GRAPH ABOVE WE HAVE NOT INCLUDED THE MAXIMUM WEIGHTED EDGE.

FOR HELP PLEASE COMMENT.
THANK YOU.


Related Solutions

Prove or disprove: If G = (V; E) is an undirected graph where every vertex has...
Prove or disprove: If G = (V; E) is an undirected graph where every vertex has degree at least 4 and u is in V , then there are at least 64 distinct paths in G that start at u.
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number...
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number of possible paths of length k ≥ 0 in G from a given starting vertex s and ending vertex t? Hint: a path of length k is a sequence of k + 1 vertices without duplicates. 2(b) What is the total number of possible paths of any length in G from a given starting vertex s and ending vertex t? 2(c) What is the...
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈...
Consider an unweighted, undirected graph G = <V, E>. The neighbourhood of a node v ∈ V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v). (a) Design an algorithm that returns a list containing the neighbourhood degree for each node v ∈...
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3...
A maximal plane graph is a plane graph G = (V, E) with n ≥ 3 vertices such that if we join any two non-adjacent vertices in G, we obtain a non-plane graph. a) Draw a maximal plane graphs on six vertices. b) Show that a maximal plane graph on n points has 3n − 6 edges and 2n − 4 faces. c) A triangulation of an n-gon is a plane graph whose infinite face boundary is a convex n-gon...
For any n ≥ 1 let Kn,n be the complete bipartite graph (V, E) where V...
For any n ≥ 1 let Kn,n be the complete bipartite graph (V, E) where V = {xi : 1 ≤ i ≤ n} ∪ {yi : 1 ≤ i ≤ n} E = {{xi , yj} : 1 ≤ i ≤ n, 1 ≤ j ≤ n} (a) Prove that Kn,n is connected for all n ≤ 1. (b) For any n ≥ 3 find two subsets of edges E 0 ⊆ E and E 00 ⊆ E such...
Let G = (V, E) be a directed graph, with source s ∈ V, sink t...
Let G = (V, E) be a directed graph, with source s ∈ V, sink t ∈ V, and nonnegative edge capacities {ce}. Give a polynomial-time algorithm to decide whether G has a unique minimum s-t cut (i.e., an s-t of capacity strictly less than that of all other s-t cuts).
Determine, for a given graph G =V,E and a positive integer m ≤ |V |, whether...
Determine, for a given graph G =V,E and a positive integer m ≤ |V |, whether G contains a clique of size m or more. (A clique of size k in a graph is its complete subgraph of k vertices.) Determine, for a given graph G = V,E and a positive integer m ≤ |V |, whether there is a vertex cover of size m or less for G. (A vertex cover of size k for a graph G =...
Prove that if G is a simple graph with |V (G)| = n even, where δ(G)...
Prove that if G is a simple graph with |V (G)| = n even, where δ(G) ≥ n 2 + 1, then G has a 3-regular spanning subgraph.
You are given an undirected graph G = ( V, E ) in which the edge...
You are given an undirected graph G = ( V, E ) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight from 1 to W, where W is a constant (independent of the number of edges or vertices). Show that it is possible to compute the single-source shortest paths in such a graph in O(E+V) time.
Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned...
Problem 8. A bipartite graph G = (V,E) is a graph whose vertices can be partitioned into two (disjoint) sets V1 and V2, such that every edge joins a vertex in V1 with a vertex in V2. This means no edges are within V1 or V2 (or symbolically: ∀u, v ∈ V1, {u,v} ∉ E and ∀u,v ∈ V2, {u,v} ∉ E). 8(a) Show that the complete graph K2 is a bipartite graph. 8(b) Prove that no complete graph Kn,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT