This document discusses algorithms for finding minimum spanning trees and shortest paths in graphs. It covers Prim's algorithm and Kruskal's algorithm for finding minimum spanning trees, and Dijkstra's algorithm for finding single-source shortest paths in graphs with non-negative edge weights. Examples are provided to illustrate how each algorithm works on sample graphs by progressively building up the minimum spanning tree or shortest path tree. Resources for further learning about data structures and algorithms are also listed.
A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
Similar to APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV0V74UXL-lBqKxDd_Fn_Bl1IAafiengGrex1nn4IL86BQsAz9cSXxnxEtInomw8hp - dmoAOJIxs59hSNWeW1JIG0Y3wzys-xz98dtB0bCspm5CRUgDmhMDo1t1C7D3dNRyEM6glz.pptx
Similar to APznzaZLM_MVouyxM4cxHPJR5BC-TAxTWqhQJ2EywQQuXStxJTDoGkHdsKEQGd4Vo7BS3Q1npCOMV0V74UXL-lBqKxDd_Fn_Bl1IAafiengGrex1nn4IL86BQsAz9cSXxnxEtInomw8hp - dmoAOJIxs59hSNWeW1JIG0Y3wzys-xz98dtB0bCspm5CRUgDmhMDo1t1C7D3dNRyEM6glz.pptx (20)
This comprehensive program covers essential aspects of performance marketing, growth strategies, and tactics, such as search engine optimization (SEO), pay-per-click (PPC) advertising, content marketing, social media marketing, and more
New Explore Careers and College Majors 2024.pdfDr. Mary Askew
Explore Careers and College Majors is a new online, interactive, self-guided career, major and college planning system.
The career system works on all devices!
For more Information, go to https://bit.ly/3SW5w8W
Want to move your career forward? Looking to build your leadership skills while helping others learn, grow, and improve their skills? Seeking someone who can guide you in achieving these goals?
You can accomplish this through a mentoring partnership. Learn more about the PMISSC Mentoring Program, where you’ll discover the incredible benefits of becoming a mentor or mentee. This program is designed to foster professional growth, enhance skills, and build a strong network within the project management community. Whether you're looking to share your expertise or seeking guidance to advance your career, the PMI Mentoring Program offers valuable opportunities for personal and professional development.
Watch this to learn:
* Overview of the PMISSC Mentoring Program: Mission, vision, and objectives.
* Benefits for Volunteer Mentors: Professional development, networking, personal satisfaction, and recognition.
* Advantages for Mentees: Career advancement, skill development, networking, and confidence building.
* Program Structure and Expectations: Mentor-mentee matching process, program phases, and time commitment.
* Success Stories and Testimonials: Inspiring examples from past participants.
* How to Get Involved: Steps to participate and resources available for support throughout the program.
Learn how you can make a difference in the project management community and take the next step in your professional journey.
About Hector Del Castillo
Hector is VP of Professional Development at the PMI Silver Spring Chapter, and CEO of Bold PM. He's a mid-market growth product executive and changemaker. He works with mid-market product-driven software executives to solve their biggest growth problems. He scales product growth, optimizes ops and builds loyal customers. He has reduced customer churn 33%, and boosted sales 47% for clients. He makes a significant impact by building and launching world-changing AI-powered products. If you're looking for an engaging and inspiring speaker to spark creativity and innovation within your organization, set up an appointment to discuss your specific needs and identify a suitable topic to inspire your audience at your next corporate conference, symposium, executive summit, or planning retreat.
About PMI Silver Spring Chapter
We are a branch of the Project Management Institute. We offer a platform for project management professionals in Silver Spring, MD, and the DC/Baltimore metro area. Monthly meetings facilitate networking, knowledge sharing, and professional development. For event details, visit pmissc.org.
4. Topics for lab session
Session Topics
1 Implementation of Minimal Spanning Tree
2 Implementation of Shortest path Algorithm
5. Learning Resources
• Fundamentals of Data Structures, E. Horowitz and S. Sahni, 1977.
• Data Structures and Algorithms, Alfred V. Aho, John E. Hopperoft,
Jeffrey D. UIlman.
• Mark Allen Weiss, Data Structures and Algorithm Analysis in C, 2nd
ed., Pearson Education, 2015
• Reema Thareja, Data Structures Using C, 1st ed., Oxford Higher
Education, 2011
• Thomas H Cormen, Charles E Leiserson, Ronald L Revest, Clifford
Stein, Introduction to Algorithms 3rd ed., The MIT Press Cambridge,
2014
6. 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.
8. 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.
9. Minimum Spanning Tree
• A spanning tree is a subset of Graph G, which has all the vertices covered with
minimum possible number of edges.
• A complete undirected graph can have maximum nn-2 number of spanning trees,
where n is number of nodes.
10. General properties of spanning tree
• A connected graph G can have more than one spanning tree.
• All possible spanning trees of graph G, have same number of edges and vertices.
• Spanning tree does not have any cycle (loops)
• Removing one edge from spanning tree will make the graph disconnected i.e.
spanning tree is minimally connected.
• Adding one edge to a spanning tree will create a cycle or loop i.e. spanning tree
is maximally acyclic.
11. Mathematical properties of spanning tree
• Spanning tree has n-1 edges, where n is number of nodes (vertices)
• From a complete graph, by removing maximum
e-n+1 edges, we can construct a spanning tree.
• A complete graph can have maximum nn-2 number of spanning trees.
• So we can conclude here that spanning trees are subset of a connected Graph G
and disconnected Graphs do not have spanning tree.
12. Application of Spanning Tree
•Spanning tree is basically used to find minimum paths to connect all
nodes in a graph.
• Civil Network Planning
• Computer Network Routing Protocol
• Cluster Analysis
13. Minimum Spanning Tree (MST)
• In a weighted graph, a minimum spanning tree is a spanning tree that has
minimum weight that all other spanning trees of the same graph.
MST Algorithm
• Kruskal’s Algorithm
• Prim’s Algorithm
Both are greedy algorithms.
14. A cable company want to connect five villages to their network which currently
extends to the market town of Avonford. What is the minimum length of cable
needed?
Avonford Fingley
Brinleigh Cornwell
Donster
Edan
2
7
4
5
8 6
4
5
3
8
Example
15. We model the situation as a network, then the problem is to find the minimum
connector for the network
A F
B C
D
E
2
7
4
5
8 6
4
5
3
8
17. Select the shortest
edge in the network
ED 2
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
18. Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
19. Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4 (or AE 4)
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
20. Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
21. Select the next shortest
edge which does not
create a cycle
ED 2
AB 3
CD 4
AE 4
BC 5 – forms a cycle
EF 5
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
22. All vertices have been
connected.
The solution is
ED 2
AB 3
CD 4
AE 4
EF 5
Total weight of tree: 18
Kruskal’s Algorithm
A
F
B
C
D
2
7
4
5
8 6
4
5
3
8
E
23. All vertices have been
connected.
The solution is
ED 2
AB 3
CD 4
AE 4
EF 5
Total weight of tree: 18
Kruskal’s Algorithm
A
F
B
C
D
2
4
5
4
3
E
24. Kruskal Algorithm
Algorithm
• Remove all loops & Parallel Edges from the given graph
• Sort all the edges in non-decreasing order of their weight.
• Pick the smallest edge. Check if it forms a cycle with the spanning tree formed so far. If
cycle is not formed, include this edge. Else, discard it.
• Repeat step#2 until there are (V-1) edges in the spanning tree.
32. Prim’s Algorithm
• Create a set mstSet that keeps track of vertices already included in MST.
• Assign a key value to all vertices in the input graph. Initialize all key
values as INFINITE. Assign key value as 0 for the first vertex so that it is
picked first.
• While mstSet doesn’t include all vertices
• Pick a vertex u which is not there in mstSet and has minimum key value.
• Include u to mstSet.
• Update key value of all adjacent vertices of u. To update the key values, iterate
through all adjacent vertices. For every adjacent vertex v, if weight of edge u-v is less
than the previous key value of v, update the key value as weight of u-v
33. Minimum Spanning Tree Algorithms
2. Select the next shortest edge
which does not create a cycle
3. Repeat step 2 until all vertices
have been connected
Kruskal’s algorithm Prim’s algorithm
1. Select the shortest edge in a 1. Select any vertex
network
2. Select the shortest edge
connected to that vertex
3. Select the shortest edge
connected to any vertex already
connected
4. Repeat step 3 until all vertices
have been connected
39. Single-Source Shortest Path Problem
Single-Source Shortest Path Problem - The problem of finding
shortest paths from a source vertex v to all other vertices in the graph.
40. Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the single-source shortest path
problem in graph theory.
Works on both directed and undirected graphs. However, all edges must
have nonnegative weights.
Input: Weighted graph G={E,V} and source vertex v∈V, such that all edge
weights are nonnegative
Output: Lengths of shortest paths (or the shortest paths themselves) from a
given source vertex v∈V to all other vertices
41. 41
Approach
• The algorithm computes for each vertex u the distance to u from the start vertex
v, that is, the weight of a shortest path between v and u.
• the algorithm keeps track of the set of vertices for which the distance has been
computed, called the cloud C
• Every vertex has a label D associated with it. For any vertex u, D[u] stores an
approximation of the distance between v and u. The algorithm will update a D[u]
value when it finds a shorter path from v to u.
• When a vertex u is added to the cloud, its label D[u] is equal to the actual (final)
distance between the starting vertex v and vertex u.
42. 42
Dijkstra pseudocode
Dijkstra(v1, v2):
for each vertex v: // Initialization
v's distance := infinity.
v's previous := none.
v1's distance := 0.
List := {all vertices}.
while List is not empty:
v := remove List vertex with minimum distance.
mark v as known.
for each unknown neighbor n of v:
dist := v's distance + edge (v, n)'s weight.
if dist is smaller than n's distance:
n's distance := dist.
n's previous := v.
reconstruct path from v2 back to v1,
following previous pointers.
43. A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 ∞
∞ ∞
∞
Pick vertex in List with minimum distance.
∞ ∞
Distance(source) = 0 Distance (all vertices
but source) = ∞
43
Example: Initialization
44. Example: Update neighbors' distance
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
∞ ∞
1
∞ ∞
Distance(B) = 2
Distance(D) = 1
44
45. Example: Remove vertex with minimum
distance
Pick vertex in List with minimum distance, i.e., D
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
∞ ∞
1
∞ ∞
45
46. Example: Update neighbors
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
3 3
1
9 5
Distance(C) = 1 + 2 = 3
Distance(E) = 1 + 2 = 3
Distance(F) = 1 + 8 = 9
Distance(G) = 1 + 4 = 5
46
47. Example: Continued...
A
G
F
B
E
C D
4 1
2
10
3
4
2
2
8
5
1
0 2
3 3
1
Pick vertex in List with minimum distance (B) and update neighbors
6
Note : distance(D) not
updated since D is
already known and
distance(E) not updated
since it is larger than
previously computed
47
9 5
48. Example: Continued...
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
3 3
1
9
48
5
No updating
Pick vertex List with minimum distance (E) and update neighbors
49. Example: Continued...
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
3 3
1
8
49
5
Pick vertex List with minimum distance (C) and update neighbors
Distance(F) = 3 + 5 = 8
50. Example: Continued...
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
3 3
1
6 5
Distance(F) = min (8, 5+1) = 6
Previous distance
Pick vertex List with minimum distance (G) and update neighbors
50
51. Example (end)
A
G
F
B
E
C D
4 1
2
10
3
6
4
2
2
8
5
1
0 2
3 3
1
Pick vertex not in S with lowest cost (F) and update neighbors
6
51
5