0% found this document useful (0 votes)
0 views

Algorithm Ch 4 Lec 2

The document discusses spanning trees in undirected connected graphs, defining them as subgraphs that are trees. It highlights applications of spanning trees, including their use in electric networks and as minimal subgraphs. Additionally, it covers minimum-cost spanning trees and algorithms such as Prim's and Kruskal's for finding these trees efficiently.

Uploaded by

Safwan Samad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Algorithm Ch 4 Lec 2

The document discusses spanning trees in undirected connected graphs, defining them as subgraphs that are trees. It highlights applications of spanning trees, including their use in electric networks and as minimal subgraphs. Additionally, it covers minimum-cost spanning trees and algorithms such as Prim's and Kruskal's for finding these trees efficiently.

Uploaded by

Safwan Samad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SPANNING TREES

❑ Definition 4.1 Let G=(V, E) be an undirected connected graph.


A subgraph t=(V, E’) of G is a spanning tree of G iff t is a tree.

Example 4.6 Figure4.5 shows the complete graph on four nodes


together with three of its spanning trees
Applications of Spanning Trees
 To obtain an independent set of circuit
equations for an electric network.
 Another application of spanning trees
arises from the property that a spanning
tree is a minimal subgraph G’ of G such
that V(G')= V(G) and G’ is connected. (A
minimal subgraphi s one with the fewest
number of edges)

10/1/2024
4.6: Minimum-Cost Spanning Trees
Definition: A minimum spanning tree (MST) of an edge-
weighted graph is a spanning tree whose weight (the sum of the
weights of its edges) is no larger than the weight of any other
spanning tree.
Example of MCST (Figure 4.6)
Finding a spanning tree of G with minimum cost

10/1/2024
Prim’s Algorithm
▪ A greedy method to obtain a minimum-cost spanning tree.
▪ How to determine the next edge to be added? The next edge to
include is chosen according to some optimization criterion.
▪ The simplest such criterion is to choose an edge that results in a
minimum increase in the sum of the costs of the edges so far
included.
▪ There are two possible ways to interpret this criterion.
• In the first, the set of edges so far selected form a tree. Thus,
if A is the set of edges selected so far, then A forms a tree.
• The next edge(u,v) to be included in A is a minimum-cost
edge not in A with the property that A U {(u,v)}is also a
tree.

10/1/2024
Prim’s Algorithm Implementation
Implementation of Prim’s algorithm
❑ Start with a tree that includes only a minimum-cost edge of G.
❑ The next edge (i,j) to be added is such that i is a vertex already
in the tree and j is a vertex not yet included.
❑ The cost[i,j] is minimum among all edges (k,l) such that vertex
k is in tree and vertex l is not in the tree.
❑ • Associate a value near[j] with each vertex j not yet included in the tree
• near[j]: a vertex in the tree such that cost[j,near[j]] is minimum among
all choices for near[j]
• near[j] = 0 for all j already in the tree.
• The next edge is defined by the vertex j such that near[j] ≠ 0 (j not
already in the tree) and cost[j, near[j]] is minimum

10/1/2024
Example 4.9(Prim’s Algorithm)
The tree starts with the edge(1,6) with minimum cost among all the
edges
Next edge to be included in the tree will be selected in the following
ways:
 near(1)=0 // already in the tree
 near(2)=1, cost(2, near(2)) = 28
 near(3)=1 (or 6), cost(3, near(3))= ∞ // no edge to the tree
near(4)=1, (or 6) cost(4, near(4)) = ∞ // no edge to the tree
 near(5)=6, cost(5, near(5)) = 25
 near(6)=0 // already in the tree
near(7)=1, (or 6), cost(7, near(7))= ∞ // no edge to the tree
 So, the next vertex is 5 and the edge to be includes is edge(6,5).
10/1/2024
Example: 4.9 (Prim’s Algorithm)

Fig: Stages in Prim’s algorithm


10/1/2024
Prim’s Algorithm

10/1/2024
Krushkal’s Algorithm

10/1/2024
Early form of the Algorithm
 Algorithm: 4.10

10/1/2024
Krushkal’s Algorithm

10/1/2024

You might also like