Seal of Good Local Governance (SGLG) 2024Final.pptx
2.4 mst prim’s algorithm
1. Spanning Trees and Minimum Spaning
Trees
spanning tree: (for connected, undirected
graph)
minimal set of edges that connect all
vertices (no cycles)
Minimum spanning tree: (for connected,
undirected and weighted graph)
minimal set of edges that connect all
vertices such that the sum of weights is
minimum.
3. Prim's Algorithm
MST=NULL;
Select an edge of min weight and add it to MST
Iteration:
repeat till n-1 edges are added to MST
1.select an edge (v1,v2) such that v1 is in MST and v2 is
not in MST
2.add it to MST
4. Prims Algorithm
Input:
A connected weighted graph G = {V, E}
Initialization:
VMST = EMST = null
Select an aribitrary vertex, x, from V
add x to VMST
Iteration:
for i = 1 to |V|-1
select an edge v1,v2 with minimum weight such that
v1 V∈ MST and v2 V V∈ MST
Add v1 to VMST
Add (v1,v2) to EMST
return EMST
5. Walk-Through
Initialize array
K dv pv
A F ∞ −
B F ∞ −
C F ∞ −
D F ∞ −
E F ∞ −
F F ∞ −
G F ∞ −
H F ∞ −
4
25
A
H
B
F
E
D
C
G 7
2
10
18
3
4
3
7
8
9
3
10
2
22. How many squares can you create in this figure by connecting any 4
dots (the corners of a square must lie upon a grid dot?
TRIANGLES:
How many triangles are located in the image below?
23. There are 11 squares total; 5 small, 4 medium, and 2 large.
27 triangles. There are 16 one-cell triangles, 7 four-cell triangles, 3 nine-cell
triangles, and 1 sixteen-cell triangle.