0% found this document useful (0 votes)
3 views29 pages

08 Minumum Spanning Tree

The document discusses Minimum Cost Spanning Trees (MCST) in connected graphs, defining key concepts such as spanning trees and minimum spanning trees (MST). It outlines three common algorithms for finding MSTs: Kruskal's, Prim's, and Borůvka's, detailing their approaches, time complexities, and use cases. Additionally, it presents an activity involving the design of an underground cable network in Istanbul using both Kruskal's and Prim's algorithms, emphasizing the differences in their outcomes due to equal-cost edge selections.

Uploaded by

gihod10765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views29 pages

08 Minumum Spanning Tree

The document discusses Minimum Cost Spanning Trees (MCST) in connected graphs, defining key concepts such as spanning trees and minimum spanning trees (MST). It outlines three common algorithms for finding MSTs: Kruskal's, Prim's, and Borůvka's, detailing their approaches, time complexities, and use cases. Additionally, it presents an activity involving the design of an underground cable network in Istanbul using both Kruskal's and Prim's algorithms, emphasizing the differences in their outcomes due to equal-cost edge selections.

Uploaded by

gihod10765
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

ANALYSIS AND DESIGN

OF ALGORITHMS

Instructor: Dr. Mert Büyükdede

1
Minumum Cost Spanning Trees (MCST)
Definition: A spanning tree of a connected graph is its connected acyclic subgraph (i.e., a tree)
that contains all the vertices of the graph.

A minimum spanning tree of a weighted connected graph is its spanning tree of the smallest
weight, where the weight of a tree is defined as the sum of the weights on all its edges.

The minimum spanning tree problem is the problem of finding a minimum spanning tree for a
given weighted connected graph.
Main Definations
Graph
A graph G=(V,E) consists of a set of vertices V (or nodes) and a set of edges E. Each edge e∈E connects
two vertices and may have an associated nonnegative weight w(e).
Connected Graph
A graph is called connected if, for every pair of vertices u,v∈V, there exists at least one path in G that leads
from u to v.
Tree
A tree is a connected acyclic graph. Equivalently, a tree with ∣V∣ vertices has exactly ∣V∣−1edges and
contains no cycles.
Spanning Tree
Given a connected graph 𝐺, a spanning tree is a subgraph T⊆G that includes all vertices of G, is connected,
and has no cycles. Therefore T also has ∣𝑉∣−1edges.
Minimum Spanning Tree (MST)
Among all spanning trees of a weighted, connected graph G, a minimum spanning tree is one whose total
edge weight sum,
is minimum. The goal is to find such a tree T.
Examples of MST
Types of MST Algorithms
Below are the three most common greedy algorithms for finding a Minimum Spanning Tree:
Algorithm Key Idea Time Complexity
Sort all edges in increasing weight
Kruskal order, then add each edge if it does O(ElogE) (using Union-Find)
not form a cycle.
Grow the tree one vertex at a time:
at each step, add the smallest-weight
Prim O(ElogV) (using a min-heap)
edge connecting the tree to a new
vertex.
In parallel, for each component select
its cheapest outgoing edge, merge
Borůvka O(ElogV)
components, and repeat until one
tree remains.

Kruskal is often preferred for sparse graphs (𝐸≪𝑉2 )


Prim is efficient on dense graphs (𝐸≈𝑉2)
Borůvka excels in large-scale or parallel implementations.
General Algorithm Framework and Common Steps
All MST algorithms share the same greedy principle:
At each step, choose the cheapest edge that can be added without violating the spanning-tree conditions
(connectedness and acyclicity).
Common Concepts
•Cut Property
For any partition (“cut”) of the vertices into two sets S and V∖S, the minimum-weight edge crossing that cut belongs to
some MST.
•Cycle Property
In any cycle, the heaviest edge cannot belong to any MST.
•Union–Find (Disjoint Set Union)
In Kruskal’s algorithm, supports
• find(u): identify which component contains u,
• union(u,v): merge the components of u and v,
both in nearly O(α(n)) amortized time.
•Min-Heap / Priority Queue
In Prim’s algorithm, lets you quickly find and update the smallest-weight edge connecting the current tree to outside
vertices.
Prim’s Algorithm:

Goal: Build a spanning tree by “growing” outward from a starting vertex, always adding the cheapest edge
that connects the current tree to a new vertex.

Key Idea: Maintain a set T of vertices that are already in the MST.
At each step, among all edges with one endpoint in T and the other outside T, choose the edge of minimum
weight—and add its outside endpoint to T. Repeat until T contains every vertex.

Why It Works: By the Cut Property, at each iteration the cheapest edge crossing the cut (𝑇,𝑉∖𝑇) must
belong to some MST. Adding that edge cannot create a cycle, because its outside endpoint was not yet in T.

Data Structures: A min-heap (or priority queue) keyed by the current best connection weight for each
outside vertex.An array key[v] holding the weight of the lightest edge known so far that connects 𝑣v to the
tree.An array parent[v] recording which tree-vertex provides that best connection.
Example of Prim’s Algorithm:

Let’s examine the graph step by step with Prim’s Algorithm.

The main goal is to never create a cycle.


Example

Let’s examine the graph step by step with Prim’s Algorithm.


Let’s create the Prim’s Algortithm using Psuedo code.
Kruksal’s Algorithm:
Kruskal's algorithm is another greedy algorithm for the minimum spanning tree problem that also
always yields an optimal solution. It is named Kruskal's algorithm, after Joseph Kruskal.

Kruskal's algorithm looks at a minimum spanning tree for a weighted connected graph G = (V, E) as
an acyclic sub graph with |V | - 1 edges for which the sum of the edge weights is the smallest.

Consequently, the algorithm constructs a minimum spanning tree as an expanding sequence of sub
graphs, which are always acyclic but are not necessarily connected on the intermediate stages of
the algorithm.

Working: The algorithm begins by sorting the graph's edges in non-decreasing order of their
weights. Then, starting with the empty subgraph, it scans this sorted list adding the next edge on
the list to the current sub graph if such an inclusion does not create a cycle and simply skipping the
edge otherwise.
In Shortly: There is no shorter path to every corner according to Kruksal's algorithm

Example
Example
In Kruskal’s algorithm, all paths are listed and sorted from smallest to largest. This list is given below for the
above graph:

x-v: 1
w-v: 1
w-u: 1
x-w: 2
u-s: 2
x-y: 3
t-u: 3
u-v: 3
y-v: 4
s-t: 4
y-z: 5
y-t: 5
z-t: 10
The cost of Kruksal’s algorithm is 16.
Let’s create the Kruksal’sAlgortithm using Psuedo code.
Let’s examine the graph step by step with Kruksal Algorithm.
Similarties and diffarences of Prim and Kruksal

Feature Prim Kruskal


Paradigm Greedy Greedy
Approach Grows a single tree from a start vertex Builds a forest, merging components
Initialization Requires a chosen start vertex No specific start vertex needed
Chooses the smallest edge from all
Edge Selection Chooses the smallest edge on the tree’s front
remaining edges
Data Structure Min-heap + adjacency list Sorted edge list + Union–Find
Time Complexity O(E log V) O(E log E) ≈ O(E log V)
Preferred For Dense graphs Sparse graphs
Precondition Connected, weighted graph Connected, weighted graph
Minimum spanning tree (total weight
Output Minimum spanning tree (total weight minimal)
minimal)
Activity: Greedy Gridlines: Powering Istanbul
from Kadıköy to Maslak

Scenario Label Location


S Kadıköy Substation
Istanbul’s Electric Works Authority has chosen A Beşiktaş Quarter
Kadıköy Substation (S) on the Anatolian side as the
B Kadıköy Residential District
new power hub.
C Üsküdar District
From this substation, they must run underground D Taksim Square
cables to seven key districts and facilities—while E Sultanahmet (Historic Peninsula)
keeping construction costs minimal. F Şişli Memorial Hospital
G Maslak Business & Industrial Zone
Your challenge is to design that network with both
Kruskal’s and Prim’s algorithms, then observe how
equal-cost “tie-breaks” produce different layouts
(though total cost stays the same).
No. From To Cost (× ₺1 000)
1 S A 10
2 S B 10
3 A B 10
4 A C 18
5 B C 18
6 B D 22
7 C D 22
8 C E 14
9 D E 8
10 E F 5
11 D F 18
12 F G 14
13 E G 6
14 B G 20
15 A G 20
Student Tasks
1. Draw the Graph

Plot nodes S–G and all 15 edges with their costs on paper or using a drawing tool.

2. Run Kruskal’s Algorithm

Sort edges by increasing cost.


Use Union–Find to add edges (skipping those creating cycles) until you have 7 edges.Record the merge
sequence, the final edge set, and total cost.

3. Run Prim’s Algorithm (start at S = Kadıköy Substation)

Initialize key[S] = 0; all others = ∞.Maintain a min-heap of vertices by key[v].Extract-min, update neighbors’
keys/parents, repeat until all 8 nodes are in the tree.List the resulting edges and compute total cost.

4. Compare & Discuss


Show the two MST edge-sets side by side. Explain how equal-cost links (the three “10” × ₺1 000 edges, etc.)
can be chosen in different order, leading to structurally different trees. Confirm both have the same total cost,
and debate which layout might be more practical for Istanbul’s urban constraints.
Kruskal’s Algorithm
Edges Sorted by Cost Union–Find Step-by-Step
Rank Edge Cost (₺×1 000)
Considered Components Component
1 E–F 5 Step Added?
Edge of Endpoints Merge
2 E–G 6
1 E–F (5) {E}, {F} Yes {E,F}
3 D–E 8
4 S–A 10 2 E–G (6) {E,F}, {G} Yes {E,F,G}
5 S–B 10 3 D–E (8) {D}, {E,F,G} Yes {D,E,F,G}
6 A–B 10 4 S–A (10) {S}, {A} Yes {S,A}
7 C–E 14 5 S–B (10) {S,A}, {B} Yes {S,A,B}
8 F–G 14
{S,A,B}, (would form a
9 A–C 18 6 A–B (10) No
{S,A,B} cycle)
10 B–C 18
7 C–E (14) {C}, {D,E,F,G} Yes {C,D,E,F,G}
11 D–F 18
{C,D,E,F,G},
12 B–G 20 8 F–G (14) No (same component)
{C,D,E,F,G}
13 A–G 20
14 B–D 22 {S,A,B}, {S,A,B,C,D,E,F,G}
9 A–C (18) Yes
{C,D,E,F,G} (all nodes linked)
15 C–D 22
2. Prim’s Algorithm (Start = S) Step Extracted Selected Edge Updates to key/parent
1 S (key=0) — A:10←S, B:10←S
Initialize: key[S]=0, all others = ∞ 2 A (key=10) S–A (10) C:18←A, G:20←A
3 B (key=10) S–B (10) D:22←B
parent[v]=NIL for all 𝑣.
4 C (key=18) A–C (18) E:14←C
All vertices in a min-heap keyed by key[]. 5 E (key=14) C–E (14) D:8←E (↓22), F:5←E, G:6←E

6 F (key=5) E–F (5) — (no neighbor improvements)

7 G (key=6) E–G (6) —


8 D (key=8) E–D (8) —
Why the Difference?

Kruskal first examines the edge S–A, S–B, then A–B (all 10s);
depending on the loop control (union-find), he can skip or
choose A–B (here he can choose and construct a different
path connecting S to A, B, A to C, then C to D).

Prim can start from S and first choose S–A and S–B, then
directly A–C or B–C according to the min-heap order, and
finally B–D or C–D.

Since the “first seen” choices they make during the tie-break
(equal cost edges) are different, the resulting tree structures
are also different.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy