mirror of
https://github.com/dholerobin/Lecture_Notes.git
synced 2025-07-01 04:56:29 +00:00
Update Kruskal's Algorithm.md
This commit is contained in:
parent
9dfb054088
commit
e5296b40a8
@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
## Kruskal's Algorithm
|
## Kruskal's Algorithm
|
||||||
|
|
||||||
Suppose, You are running a company with several offices in different cities. Now, you want to connect all the offices by phone lines. Different networking companies are asking for different amount of money to connect different pairs of offices.
|
Suppose, You are running a company with several offices in different cities. Now, you want to connect all the offices by phone lines. Different networking companies are asking for different amount of money to connect different pairs of offices.
|
||||||
|
|
||||||

|

|
||||||
***Comp** is an abbreviation of Company.
|
***Comp** is an abbreviation of Company.
|
||||||
|
|
||||||
Now, how will you figure out the way with minimum cost?
|
Now, how will you figure out the way with minimum cost?
|
||||||
@ -22,9 +21,9 @@ $Q.1$ What is the minimum possible number of edges that can connect all the vert
|
|||||||
|
|
||||||
Answer: $|V|-1$
|
Answer: $|V|-1$
|
||||||
|
|
||||||
$Q.2$ Find one ST for the following graph.
|
$Q.2$ Find one ST for the following graph.
|
||||||
**Answer:** Dark lines represents the spanning tree which is not unique.
|
**Answer:** Dark lines represents the spanning tree which is not unique.
|
||||||

|

|
||||||
|
|
||||||
### Minimum Spanning Tree (MST)
|
### Minimum Spanning Tree (MST)
|
||||||
Minimum Spanning Tree is the Spanning Tree with minimum cost.
|
Minimum Spanning Tree is the Spanning Tree with minimum cost.
|
||||||
@ -33,15 +32,15 @@ Here the cost has different meanings for different kinds of problem. For example
|
|||||||
|
|
||||||
### Quiz Time
|
### Quiz Time
|
||||||
Find the MST for the given graph.
|
Find the MST for the given graph.
|
||||||

|

|
||||||
|
|
||||||
**Answer:**
|
**Answer:**
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
**Note**: Here we are talking about an undirected graph because directed graph may or may not have ST. See the image below:
|
**Note**: Here we are talking about an undirected graph because directed graph may or may not have ST. See the image below:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
For a directed graph to have a ST, there must be a vertex (say "$root$") from which we can reach to every other vetex by directed paths.
|
For a directed graph to have a ST, there must be a vertex (say "$root$") from which we can reach to every other vetex by directed paths.
|
||||||
|
|
||||||
@ -79,13 +78,13 @@ Kruskal's Algorithm is a **greedy algorithm**, which chooses the least weighted
|
|||||||
At the end of the algorithm there will be only one connected component, which includes each vertex of the graph.
|
At the end of the algorithm there will be only one connected component, which includes each vertex of the graph.
|
||||||
|
|
||||||
**Visualization**
|
**Visualization**
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
Are you wondering how we will do the step $2$ of the algorithm? Which is to find whether two vertices are already connected.
|
Are you wondering how we will do the step $2$ of the algorithm? Which is to find whether two vertices are already connected.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user