Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae15b8e

Browse files
graph codes
1 parent dbedb50 commit ae15b8e

File tree

8 files changed

+1028
-160
lines changed

8 files changed

+1028
-160
lines changed

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Kruskal’s Algorithm/.ipynb_checkpoints/Kruskal’s Algorithm-checkpoint.ipynb‎

Lines changed: 294 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Kruskal’s Minimum Spanning Tree (MST) Algorithm
2+
3+
### Introduction
4+
5+
Kruskal’s Algorithm is a well-known greedy algorithm designed to find the minimum spanning tree (MST) of a connected, undirected graph. Similar to Prim's Algorithm, the objective of Kruskal's Algorithm is to connect all vertices of the graph with the minimum possible total edge weight. This algorithm is particularly useful in scenarios such as network design, where the goal is to establish a cost-effective and optimal network of roads, pipelines, or communication channels.
6+
7+
## Kruskal’s Algorithm Pseudocode
8+
9+
1. **Initialize an empty set MST** to store the minimum spanning tree.
10+
11+
2. **Sort all the edges in non-decreasing order** of their weights.
12+
13+
3. **Initialize a disjoint set (or union-find) data structure** to keep track of connected components.
14+
15+
4. **For each edge in the sorted list:**
16+
- If including the edge does not create a cycle in MST (i.e., the edge connects two disjoint sets):
17+
- Add the edge to MST.
18+
- Merge the two sets connected by the edge.
19+
20+
5. **Return MST.**
21+
22+
### Purpose
23+
24+
The primary purpose of Kruskal’s Algorithm is to identify a subset of edges forming a tree that spans all vertices in the graph, while minimizing the total weight of the edges. This optimization is crucial in various network-related problems, ensuring the establishment of an efficient and cost-effective connected infrastructure.
25+
26+
### Time Complexity
27+
28+
The time complexity of Kruskal’s Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. The dominating factor is the sorting of edges by weight.
29+
30+
### Space Complexity
31+
32+
The space complexity of Kruskal’s Algorithm is O(E + V), where E is the number of edges and V is the number of vertices in the graph. This accounts for the space used to store the minimum spanning tree (MST), the edges, and the disjoint set data structure.
33+
34+
### Applications
35+
36+
Kruskal’s Algorithm finds applications in various domains:
37+
38+
- **Network Design**: Efficiently designing networks for communication, transportation, or resource distribution.
39+
40+
- **Clustering**: Identifying clusters or groups in data for analysis.
41+
42+
- **Maze Generation**: Creating mazes with optimal paths.
43+
44+
- **Circuit Design**: Optimizing the layout of electronic circuits.

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Kruskal’s Algorithm/Kruskal’s Algorithm.ipynb‎

Lines changed: 294 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Kruskal’s Minimum Spanning Tree (MST) Algorithm
2+
3+
### Introduction
4+
5+
Kruskal’s Algorithm is a well-known greedy algorithm designed to find the minimum spanning tree (MST) of a connected, undirected graph. Similar to Prim's Algorithm, the objective of Kruskal's Algorithm is to connect all vertices of the graph with the minimum possible total edge weight. This algorithm is particularly useful in scenarios such as network design, where the goal is to establish a cost-effective and optimal network of roads, pipelines, or communication channels.
6+
7+
## Kruskal’s Algorithm Pseudocode
8+
9+
1. **Initialize an empty set MST** to store the minimum spanning tree.
10+
11+
2. **Sort all the edges in non-decreasing order** of their weights.
12+
13+
3. **Initialize a disjoint set (or union-find) data structure** to keep track of connected components.
14+
15+
4. **For each edge in the sorted list:**
16+
- If including the edge does not create a cycle in MST (i.e., the edge connects two disjoint sets):
17+
- Add the edge to MST.
18+
- Merge the two sets connected by the edge.
19+
20+
5. **Return MST.**
21+
22+
### Purpose
23+
24+
The primary purpose of Kruskal’s Algorithm is to identify a subset of edges forming a tree that spans all vertices in the graph, while minimizing the total weight of the edges. This optimization is crucial in various network-related problems, ensuring the establishment of an efficient and cost-effective connected infrastructure.
25+
26+
### Time Complexity
27+
28+
The time complexity of Kruskal’s Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. The dominating factor is the sorting of edges by weight.
29+
30+
### Space Complexity
31+
32+
The space complexity of Kruskal’s Algorithm is O(E + V), where E is the number of edges and V is the number of vertices in the graph. This accounts for the space used to store the minimum spanning tree (MST), the edges, and the disjoint set data structure.
33+
34+
### Applications
35+
36+
Kruskal’s Algorithm finds applications in various domains:
37+
38+
- **Network Design**: Efficiently designing networks for communication, transportation, or resource distribution.
39+
40+
- **Clustering**: Identifying clusters or groups in data for analysis.
41+
42+
- **Maze Generation**: Creating mazes with optimal paths.
43+
44+
- **Circuit Design**: Optimizing the layout of electronic circuits.

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Prim's Algorithm/.ipynb_checkpoints/Prim's Algorithm-checkpoint.ipynb‎

Lines changed: 166 additions & 69 deletions
Large diffs are not rendered by default.

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Prim's Algorithm/.ipynb_checkpoints/READme-checkpoint.md‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ Prim's Algorithm is a popular greedy algorithm used for finding the minimum span
2626

2727
The main purpose of Prim's Algorithm is to find a subset of edges that forms a tree including every vertex, where the total weight of all the edges in the tree is minimized. This helps in optimizing various network-related problems, ensuring that the connected infrastructure is both cost-effective and efficient.
2828

29+
### Time Complexity
30+
31+
The time complexity of Prim's Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. This is mainly due to the priority queue operations.
32+
33+
### Space Complexity
34+
35+
The space complexity of Prim's Algorithm is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This accounts for the space used to store the minimum spanning tree (MST) and the priority queue.
36+
37+
2938
### Applications
3039

3140
Prim's Algorithm finds applications in various domains:
@@ -36,14 +45,4 @@ Prim's Algorithm finds applications in various domains:
3645

3746
- **Maze Generation**: Creating mazes with corridors that are as short as possible.
3847

39-
- **Circuit Design**: Optimizing the layout of electronic circuits.
40-
41-
42-
### Time Complexity
43-
44-
The time complexity of Prim's Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. This is mainly due to the priority queue operations.
45-
46-
### Space Complexity
47-
48-
The space complexity of Prim's Algorithm is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This accounts for the space used to store the minimum spanning tree (MST) and the priority queue.
49-
48+
- **Circuit Design**: Optimizing the layout of electronic circuits.

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Prim's Algorithm/Prim's Algorithm.ipynb‎

Lines changed: 166 additions & 69 deletions
Large diffs are not rendered by default.

‎Graphs Algorithims/Minimum Spanning Tree Algorthims/Prim's Algorithm/READme.md‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ Prim's Algorithm is a popular greedy algorithm used for finding the minimum span
2626

2727
The main purpose of Prim's Algorithm is to find a subset of edges that forms a tree including every vertex, where the total weight of all the edges in the tree is minimized. This helps in optimizing various network-related problems, ensuring that the connected infrastructure is both cost-effective and efficient.
2828

29+
### Time Complexity
30+
31+
The time complexity of Prim's Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. This is mainly due to the priority queue operations.
32+
33+
### Space Complexity
34+
35+
The space complexity of Prim's Algorithm is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This accounts for the space used to store the minimum spanning tree (MST) and the priority queue.
36+
37+
2938
### Applications
3039

3140
Prim's Algorithm finds applications in various domains:
@@ -36,14 +45,4 @@ Prim's Algorithm finds applications in various domains:
3645

3746
- **Maze Generation**: Creating mazes with corridors that are as short as possible.
3847

39-
- **Circuit Design**: Optimizing the layout of electronic circuits.
40-
41-
42-
### Time Complexity
43-
44-
The time complexity of Prim's Algorithm is O(E log V), where E is the number of edges and V is the number of vertices in the graph. This is mainly due to the priority queue operations.
45-
46-
### Space Complexity
47-
48-
The space complexity of Prim's Algorithm is O(V + E), where V is the number of vertices and E is the number of edges in the graph. This accounts for the space used to store the minimum spanning tree (MST) and the priority queue.
49-
48+
- **Circuit Design**: Optimizing the layout of electronic circuits.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /