SlideShare a Scribd company logo
1
Spanning Trees
2
Graph - Spanning Tree
• A tree that contains every vertex of a connected graph is
called spanning tree. It is an undirected tree consisting
of only those edges that are necessary to connect all the
vertices of the original graph G.
• CHARACTERISTICS
1. It is a subgraph of a graph G that contain all the
vertex of graph G.
2. For any pair of vertices, there exists only one path
between them.
3. It is a connected graph with no cycles.
4. A graph may have many spanning tree.
3
EXAMPLE
4
Graph - Minimum Spanning Tree
• Let G=(V,E,W) be any weighted graph. Then a
spanning tree whose cost is minimum is
called minimum spanning tree. The cost of the
spanning tree is defined as the sum of the
costs of the edges in that tree.
5
Kruskal's algorithm
• It is an algorithm in graph theory that finds a minimum
spanning tree for a connected weighted graph.
• It finds a subset of the edges that forms a tree that
includes every vertex, where the total weight of all the
edges in the tree is minimized.
• If the graph is not connected, then it finds a minimum
spanning forest (a minimum spanning tree for each
connected component).
• Kruskal's algorithm is an example of a greedy algorithm.
6
1. Create a forest F (a set of trees), where each vertex in
the graph is a separate tree
2. Create a set S containing all the edges in the graph
3. Repeat Step 4 and 5, while S is nonempty and F is not
yet spanning
4. Remove an edge with minimum weight from S
5. IF that edge connects two different trees, then add it to
the forest, combining two trees into a single tree ELSE
discard that edge.
6. Exit
At the termination of the algorithm, the forest has only
one component and forms a minimum spanning tree of
the graph.
7
Example of Kruskal’s Algorithm
This is our original graph. The numbers near the
arcs indicate their weight. None of the arcs are
highlighted.
8
AD and CE are the shortest
arcs, with length 5, and AD
has been arbitrarily chosen,
so it is highlighted.
CE is now the shortest arc
that does not form a cycle,
with length 5, so it is
highlighted as the second
arc.
9
The next arc, DF with length 6,
is highlighted using much the
same method.
The next-shortest arcs are AB and BE,
both with length 7. AB is chosen
arbitrarily, and is highlighted. The arc
BD has been highlighted in red,
because there already exists a path
(in green) between B andD, so it
would form a cycle (ABD) if it were
chosen.
10
The process continues to
highlight the next-smallest arc,
BE with length 7. Many more arcs
are highlighted in red at this
stage: BC because it would form
the loop BCE, DE because it
would form the loop DEBA, and
FE because it would form FEBAD.
Finally, the process finishes with
the arc EG of length 9, and the
minimum spanning tree is found.
11
Prim's algorithm
• It is a greedy algorithm that finds a minimum
spanning tree for a connected weighted
undirected graph.
• Same as in Kruskal’s Algorithm, it finds a
subset of the edges that forms a tree that
includes every vertex, where the total weight
of all the edges in the tree is minimized.
• It is also sometimes called the DJP algorithm,
the Jarnik algorithm, or the Prim–Jarnik
algorithm.
12
Prim's algorithm (contd..)
• The only spanning tree of the empty graph
(with an empty vertex set) is again the empty
graph.
• The following description assumes that this
special case is handled separately.
• The algorithm continuously increases the size
of a tree, one edge at a time, starting with a
tree consisting of a single vertex, until it spans
all vertices.
13
• Input: A non-empty connected weighted graph with
vertices V and edges E (the weights can be negative).
Algorithm:
1. Initialize: Vnew = {x}, where x is an arbitrary node (starting
point) from V, Enew = { }
2. Repeat Step 3 and 4, until Vnew = V
3. Choose an edge (u, v) with minimal weight such that u is
in Vnew and v is not (if there are multiple edges with the
same weight, any of them may be picked)
4. Add v to Vnew, and (u, v) to Enew
5. Exit
• Output: Vnew and Enew describe a minimal spanning tree
14
Example of Prim’s Algorithm
This is our original weighted graph. The numbers
near the edges indicate their weight.
15
Vertex D has been arbitrarily
chosen as a starting point. Vertices
A, B, E and F are connected to D
through a single edge. A is the
vertex nearest to D and will be
chosen as the second vertex along
with the edge AD.
The next vertex chosen is the
vertex nearest to either D or A. B is
9 away from D and 7 away
from A, E is 15, and F is 6. F is the
smallest distance away, so we
highlight the vertex F and the
arc DF.
16
The algorithm carries on as
above. Vertex B, which is 7
away from A, is highlighted.
In this case, we can choose
between C, E, and G. C is 8
away from B, E is 7 away
from B, and G is 11 away
from F. E is nearest, so we
highlight the vertex E and
the arc BE.
17
Here, the only vertices
available are C and G. C is 5
away from E, and G is 9 away
from E. C is chosen, so it is
highlighted along with the
arc EC.
Vertex G is the only
remaining vertex. It is 11
away from F, and 9 away
from E. E is nearer, so we
highlight it and the arc EG.
18
Now all the vertices have
been selected and the
minimum spanning tree is
shown in green. In this case,
it has weight 39.
19
U Edge(u,v) V - U
{ } {A,B,C,D,E,F,G}
{D}
(D,A) = 5 V
(D,B) = 9
(D,E) = 15
(D,F) = 6
{A,B,C,E,F,G}
{A,D}
(D,B) = 9
(D,E) = 15
(D,F) =6 V
(A,B) = 7
{B,C,E,F,G}
{A,D,F}
(D,B) = 9
(D,E) = 15
(A,B) = 7 V
(F,E) = 8
(F,G) = 11
{B,C,E,G}
{A,B,D,F}
(B,C) = 8
(B,E) = 7 V
(D,B) = 9 cycle
(D,E) = 15
(F,E) = 8
(F,G) = 11
{C,E,G}
{A,B,D,E,F}
(B,C) = 8
(D,B) = 9 cycle
(D,E) = 15 cycle
(E,C) = 5 V
(E,G) = 9
(F,E) = 8 cycle
(F,G) = 11
{C,G}
{A,B,C,D,E,F}
(B,C) = 8 cycle
(D,B) = 9 cycle
(D,E) = 15 cycle
(E,G) = 9 V
(F,E) = 8 cycle
(F,G) = 11
{G}
{A,B,C,D,E,F,G}
(B,C) = 8 cycle
(D,B) = 9 cycle
(D,E) = 15 cycle
(F,E) = 8 cycle
(F,G) = 11 cycle
{ }

More Related Content

What's hot

Geometry unit 6.6
Geometry unit 6.6Geometry unit 6.6
Geometry unit 6.6
Mark Ryder
 
Geometry unit 7.1
Geometry unit 7.1Geometry unit 7.1
Geometry unit 7.1
Mark Ryder
 
8.7 coordinate proof with quadrilaterals
8.7 coordinate proof with quadrilaterals8.7 coordinate proof with quadrilaterals
8.7 coordinate proof with quadrilaterals
detwilerr
 
Geometry unit 7.3
Geometry unit 7.3Geometry unit 7.3
Geometry unit 7.3
Mark Ryder
 
Geometry 201 unit 5.7
Geometry 201 unit 5.7Geometry 201 unit 5.7
Geometry 201 unit 5.7
Mark Ryder
 
Graph Theory: Cut-Set and Cut-Vertices
Graph Theory: Cut-Set and Cut-VerticesGraph Theory: Cut-Set and Cut-Vertices
Graph Theory: Cut-Set and Cut-Vertices
Ashikur Rahman
 
Geometry unit 7.2
Geometry unit 7.2Geometry unit 7.2
Geometry unit 7.2
Mark Ryder
 
Geometry unit 7.4
Geometry unit 7.4Geometry unit 7.4
Geometry unit 7.4
Mark Ryder
 
Chapter 5 unit f 001
Chapter 5 unit f 001Chapter 5 unit f 001
Chapter 5 unit f 001
jbianco9910
 
6.6 use proportionality theorems
6.6 use proportionality theorems6.6 use proportionality theorems
6.6 use proportionality theorems
detwilerr
 
Geometry unit 6.4
Geometry unit 6.4Geometry unit 6.4
Geometry unit 6.4
Mark Ryder
 
11.6 area of reg polygons
11.6 area of reg polygons11.6 area of reg polygons
11.6 area of reg polygons
guesta7a51cbc
 
8.5 use properties of trapezoids and kites
8.5 use properties of trapezoids and kites8.5 use properties of trapezoids and kites
8.5 use properties of trapezoids and kites
detwilerr
 
Geometry unit 6.2
Geometry unit 6.2Geometry unit 6.2
Geometry unit 6.2
Mark Ryder
 
Chapter 5 unit f 001
Chapter 5 unit f 001Chapter 5 unit f 001
Chapter 5 unit f 001
jbianco9910
 
Bs33424429
Bs33424429Bs33424429
Bs33424429
IJERA Editor
 
8.6 identify special quadrilaterals
8.6 identify special quadrilaterals8.6 identify special quadrilaterals
8.6 identify special quadrilaterals
detwilerr
 
The Arbelos
The ArbelosThe Arbelos
The Arbelos
sov1
 
Geometry unit 4.5
Geometry unit 4.5Geometry unit 4.5
Geometry unit 4.5
Mark Ryder
 

What's hot (19)

Geometry unit 6.6
Geometry unit 6.6Geometry unit 6.6
Geometry unit 6.6
 
Geometry unit 7.1
Geometry unit 7.1Geometry unit 7.1
Geometry unit 7.1
 
8.7 coordinate proof with quadrilaterals
8.7 coordinate proof with quadrilaterals8.7 coordinate proof with quadrilaterals
8.7 coordinate proof with quadrilaterals
 
Geometry unit 7.3
Geometry unit 7.3Geometry unit 7.3
Geometry unit 7.3
 
Geometry 201 unit 5.7
Geometry 201 unit 5.7Geometry 201 unit 5.7
Geometry 201 unit 5.7
 
Graph Theory: Cut-Set and Cut-Vertices
Graph Theory: Cut-Set and Cut-VerticesGraph Theory: Cut-Set and Cut-Vertices
Graph Theory: Cut-Set and Cut-Vertices
 
Geometry unit 7.2
Geometry unit 7.2Geometry unit 7.2
Geometry unit 7.2
 
Geometry unit 7.4
Geometry unit 7.4Geometry unit 7.4
Geometry unit 7.4
 
Chapter 5 unit f 001
Chapter 5 unit f 001Chapter 5 unit f 001
Chapter 5 unit f 001
 
6.6 use proportionality theorems
6.6 use proportionality theorems6.6 use proportionality theorems
6.6 use proportionality theorems
 
Geometry unit 6.4
Geometry unit 6.4Geometry unit 6.4
Geometry unit 6.4
 
11.6 area of reg polygons
11.6 area of reg polygons11.6 area of reg polygons
11.6 area of reg polygons
 
8.5 use properties of trapezoids and kites
8.5 use properties of trapezoids and kites8.5 use properties of trapezoids and kites
8.5 use properties of trapezoids and kites
 
Geometry unit 6.2
Geometry unit 6.2Geometry unit 6.2
Geometry unit 6.2
 
Chapter 5 unit f 001
Chapter 5 unit f 001Chapter 5 unit f 001
Chapter 5 unit f 001
 
Bs33424429
Bs33424429Bs33424429
Bs33424429
 
8.6 identify special quadrilaterals
8.6 identify special quadrilaterals8.6 identify special quadrilaterals
8.6 identify special quadrilaterals
 
The Arbelos
The ArbelosThe Arbelos
The Arbelos
 
Geometry unit 4.5
Geometry unit 4.5Geometry unit 4.5
Geometry unit 4.5
 

Similar to 7. Spanning trees

Ds lec 5_chap4
Ds lec 5_chap4Ds lec 5_chap4
Ds lec 5_chap4
Self-Employed
 
Mithfh lecturenotes 9
Mithfh lecturenotes 9Mithfh lecturenotes 9
Mithfh lecturenotes 9
Praveen Kumar
 
nossi ch 6
nossi ch 6nossi ch 6
nossi ch 6
lesaturner
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
Shareb Ismaeel
 
Graph clustering
Graph clusteringGraph clustering
Graph clustering
ssusered887b
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
satvikkushwaha1
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
KENNEDY GITHAIGA
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
SwarndeviKm
 
Graphs
GraphsGraphs
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
Core Condor
 
Graph ds
Graph dsGraph ds
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
KENNEDY GITHAIGA
 
Graph theory1234
Graph theory1234Graph theory1234
Graph theory1234
muhamadsyafiqzaini
 
Magtibay buk bind#2
Magtibay buk bind#2Magtibay buk bind#2
Magtibay buk bind#2
Sofia Palawan
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13
sumitbardhan
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
DhruvilSTATUS
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
KUSHDHIRRA2111026030
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
MuhammadUmerIhtisham
 
spanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdfspanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdf
YasirAli74993
 

Similar to 7. Spanning trees (20)

Ds lec 5_chap4
Ds lec 5_chap4Ds lec 5_chap4
Ds lec 5_chap4
 
Mithfh lecturenotes 9
Mithfh lecturenotes 9Mithfh lecturenotes 9
Mithfh lecturenotes 9
 
nossi ch 6
nossi ch 6nossi ch 6
nossi ch 6
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Graph clustering
Graph clusteringGraph clustering
Graph clustering
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Graphs
GraphsGraphs
Graphs
 
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
 
Graph ds
Graph dsGraph ds
Graph ds
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Graph theory1234
Graph theory1234Graph theory1234
Graph theory1234
 
Magtibay buk bind#2
Magtibay buk bind#2Magtibay buk bind#2
Magtibay buk bind#2
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV...
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
spanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdfspanningtreesapplications-120903115339-phpapp02 (1).pdf
spanningtreesapplications-120903115339-phpapp02 (1).pdf
 

More from Mandeep Singh

9.Sorting & Searching
9.Sorting & Searching9.Sorting & Searching
9.Sorting & Searching
Mandeep Singh
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
Mandeep Singh
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
Mandeep Singh
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
Mandeep Singh
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
Mandeep Singh
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
Mandeep Singh
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented Programming
Mandeep Singh
 
Ip6 tables in linux
Ip6 tables in linuxIp6 tables in linux
Ip6 tables in linux
Mandeep Singh
 
Iptables in linux
Iptables in linuxIptables in linux
Iptables in linux
Mandeep Singh
 

More from Mandeep Singh (11)

9.Sorting & Searching
9.Sorting & Searching9.Sorting & Searching
9.Sorting & Searching
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
 
6. Graphs
6. Graphs6. Graphs
6. Graphs
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented Programming
 
Ip6 tables in linux
Ip6 tables in linuxIp6 tables in linux
Ip6 tables in linux
 
Iptables in linux
Iptables in linuxIptables in linux
Iptables in linux
 

Recently uploaded

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 

Recently uploaded (20)

Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 

7. Spanning trees

  • 2. 2 Graph - Spanning Tree • A tree that contains every vertex of a connected graph is called spanning tree. It is an undirected tree consisting of only those edges that are necessary to connect all the vertices of the original graph G. • CHARACTERISTICS 1. It is a subgraph of a graph G that contain all the vertex of graph G. 2. For any pair of vertices, there exists only one path between them. 3. It is a connected graph with no cycles. 4. A graph may have many spanning tree.
  • 4. 4 Graph - Minimum Spanning Tree • Let G=(V,E,W) be any weighted graph. Then a spanning tree whose cost is minimum is called minimum spanning tree. The cost of the spanning tree is defined as the sum of the costs of the edges in that tree.
  • 5. 5 Kruskal's algorithm • It is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. • It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. • If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component). • Kruskal's algorithm is an example of a greedy algorithm.
  • 6. 6 1. Create a forest F (a set of trees), where each vertex in the graph is a separate tree 2. Create a set S containing all the edges in the graph 3. Repeat Step 4 and 5, while S is nonempty and F is not yet spanning 4. Remove an edge with minimum weight from S 5. IF that edge connects two different trees, then add it to the forest, combining two trees into a single tree ELSE discard that edge. 6. Exit At the termination of the algorithm, the forest has only one component and forms a minimum spanning tree of the graph.
  • 7. 7 Example of Kruskal’s Algorithm This is our original graph. The numbers near the arcs indicate their weight. None of the arcs are highlighted.
  • 8. 8 AD and CE are the shortest arcs, with length 5, and AD has been arbitrarily chosen, so it is highlighted. CE is now the shortest arc that does not form a cycle, with length 5, so it is highlighted as the second arc.
  • 9. 9 The next arc, DF with length 6, is highlighted using much the same method. The next-shortest arcs are AB and BE, both with length 7. AB is chosen arbitrarily, and is highlighted. The arc BD has been highlighted in red, because there already exists a path (in green) between B andD, so it would form a cycle (ABD) if it were chosen.
  • 10. 10 The process continues to highlight the next-smallest arc, BE with length 7. Many more arcs are highlighted in red at this stage: BC because it would form the loop BCE, DE because it would form the loop DEBA, and FE because it would form FEBAD. Finally, the process finishes with the arc EG of length 9, and the minimum spanning tree is found.
  • 11. 11 Prim's algorithm • It is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. • Same as in Kruskal’s Algorithm, it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. • It is also sometimes called the DJP algorithm, the Jarnik algorithm, or the Prim–Jarnik algorithm.
  • 12. 12 Prim's algorithm (contd..) • The only spanning tree of the empty graph (with an empty vertex set) is again the empty graph. • The following description assumes that this special case is handled separately. • The algorithm continuously increases the size of a tree, one edge at a time, starting with a tree consisting of a single vertex, until it spans all vertices.
  • 13. 13 • Input: A non-empty connected weighted graph with vertices V and edges E (the weights can be negative). Algorithm: 1. Initialize: Vnew = {x}, where x is an arbitrary node (starting point) from V, Enew = { } 2. Repeat Step 3 and 4, until Vnew = V 3. Choose an edge (u, v) with minimal weight such that u is in Vnew and v is not (if there are multiple edges with the same weight, any of them may be picked) 4. Add v to Vnew, and (u, v) to Enew 5. Exit • Output: Vnew and Enew describe a minimal spanning tree
  • 14. 14 Example of Prim’s Algorithm This is our original weighted graph. The numbers near the edges indicate their weight.
  • 15. 15 Vertex D has been arbitrarily chosen as a starting point. Vertices A, B, E and F are connected to D through a single edge. A is the vertex nearest to D and will be chosen as the second vertex along with the edge AD. The next vertex chosen is the vertex nearest to either D or A. B is 9 away from D and 7 away from A, E is 15, and F is 6. F is the smallest distance away, so we highlight the vertex F and the arc DF.
  • 16. 16 The algorithm carries on as above. Vertex B, which is 7 away from A, is highlighted. In this case, we can choose between C, E, and G. C is 8 away from B, E is 7 away from B, and G is 11 away from F. E is nearest, so we highlight the vertex E and the arc BE.
  • 17. 17 Here, the only vertices available are C and G. C is 5 away from E, and G is 9 away from E. C is chosen, so it is highlighted along with the arc EC. Vertex G is the only remaining vertex. It is 11 away from F, and 9 away from E. E is nearer, so we highlight it and the arc EG.
  • 18. 18 Now all the vertices have been selected and the minimum spanning tree is shown in green. In this case, it has weight 39.
  • 19. 19 U Edge(u,v) V - U { } {A,B,C,D,E,F,G} {D} (D,A) = 5 V (D,B) = 9 (D,E) = 15 (D,F) = 6 {A,B,C,E,F,G} {A,D} (D,B) = 9 (D,E) = 15 (D,F) =6 V (A,B) = 7 {B,C,E,F,G} {A,D,F} (D,B) = 9 (D,E) = 15 (A,B) = 7 V (F,E) = 8 (F,G) = 11 {B,C,E,G} {A,B,D,F} (B,C) = 8 (B,E) = 7 V (D,B) = 9 cycle (D,E) = 15 (F,E) = 8 (F,G) = 11 {C,E,G} {A,B,D,E,F} (B,C) = 8 (D,B) = 9 cycle (D,E) = 15 cycle (E,C) = 5 V (E,G) = 9 (F,E) = 8 cycle (F,G) = 11 {C,G} {A,B,C,D,E,F} (B,C) = 8 cycle (D,B) = 9 cycle (D,E) = 15 cycle (E,G) = 9 V (F,E) = 8 cycle (F,G) = 11 {G} {A,B,C,D,E,F,G} (B,C) = 8 cycle (D,B) = 9 cycle (D,E) = 15 cycle (F,E) = 8 cycle (F,G) = 11 cycle { }