0% found this document useful (0 votes)
18 views

Prim's Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Prim's Algorithm

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Data Structures: Prim’s Algorithm

TABLE OF CONTENTS

CHAPTER 1: INTRODUCTION
I.1 Introduction
I.2 Problem Statement
I.3 Objectives

CHAPTER 2: LITERATURE REVIEW


II.1 Literature Review
II.1.1 Background and Motivation
II.1.2 Supporting Literature

CHAPTER 3: METHODS
III.1 Implementation Details
III.2 Time Complexity

CHAPTER IV: COMPARATIVE ANALYSIS


IV.1: Comparison with Other Algorithms
IV.2: Results and Findings

CHAPTER V: CONCLUSION
V.1: Summary of Findings
V.2: Real-World Applications

REFERENCES:
CHAPTER I
INTRODUCTION

I.1 Introduction

Prim’s algorithm is a greedy algorithm used to find the Minimum Spanning Tree (MST) of
a connected, undirected graph. The purpose of this algorithm is to find the minimum spanning
tree (MST), which is a subset of the edges that connects all vertices in the graph with the
minimum possible total edge weight. It is widely used to design a network that minimizes cost
including communication networks, circuit layout, road network, and more. Through the
implementation of priority queue or binary heaps, simple array, and adjacency list or matrices,
Prim’s algorithm is efficient to use and making it suitable for graphs with a large number of edges,
such as dense graphs.

Utilizing Prim's Algorithm, we can efficiently construct the MST of the given graph,
subsequently enabling optimized solutions in various situations and for numerous applications.

I.2 Problem Statement

Defined Problem: Identifying a subset of edges from a given weighted graph that connects all
vertices with the minimum possible total edge weight and without forming any cycles. Thus, this
algorithm is designed to solve the minimum spanning tree (MST).

I.3 Objectives
1. The primary goal of Prim’s algorithm is to find a subset of edges that connects all
vertices in the graph with the minimum possible total edge weight.
2. Creates a spanning tree by adding the shortest edges that connect a vertex in the MST
to a vertex outside the MST.
3. The algorithm ensures to build a tree without forming any cycle.
4. To efficiently select the minimum edge weight by using primary queues, binary heaps,
simple array, adjacency list or adjacency matrix.
CHAPTER II
LITERATURE REVIEW

II.1 Background and Motivation:

Prim's algorithm was invented in 1930 by the Czech mathematician Vojtěch Jarník.The
algorithm was then rediscovered by Robert C. Prim in 1957, and also rediscovered by Edsger W.
Dijkstra in 1959. Therefore, the algorithm is also sometimes called "Jarník's algorithm", or the
"Prim-Jarník algorithm".

The need to solve network design problems efficiently was the driving force behind the
development of Prim’s algorithm. In real-world situations, such as installing telephone lines,
establishing computer networks, or constructing transportation routes, it is critical to minimize
the total length or cost of the connections. Prior to the development of algorithms like Prim’s,
these problems were solved manually or using less efficient methods that were not suitable for
large graphs. Prim's algorithm tackles this challenge by offering an automated and efficient
approach to minimizing costs while maintaining connectivity across the entire network. Its
capability to identify an optimal solution without having to examine all possible edge
combinations has established it as a valuable tool in both theoretical and applied computer
science.

II.2 Supporting Literature:

International Journal of Computer Science and Technology. "Review and Analysis of Minimum
Spanning Tree Using Prim's Algorithm" (2018). This paper presents an in-depth analysis of Prim's
algorithm and compares its performance in solving real-world network problems.

P. Ayegba, J. Ayoola, E. Asani and A. Okeyinka, "A Comparative Study Of Minimal Spanning Tree
Algorithms," 2020. The study focuses on comparing the performance and efficiency of different
MST algorithms, including Prim’s Algorithm, Kruskal’s Algorithm, and potentially others. The
paper may also include empirical results from experiments conducted to demonstrate the
strengths and weaknesses of each algorithm in various scenarios. By providing a comparative
analysis, the study aims to offer valuable insights into the selection of the most appropriate MST
algorithm for specific applications and problem contexts.

Munier, B., Aleem, M., Islam, M. A., Iqbal, M. A., & Mehmood, W. (2017).”A Fast Implementation
of Minimum Spanning Tree Method and Applying it to Kruskal’s and Prim’s Algorithms”. The study
focuses on developing and applying fast implementation techniques for MST algorithms,
specifically Kruskal’s and Prim’s algorithms. The authors address the efficiency of these algorithms
through optimized implementations that reduce computational time and enhance performance.
The paper includes a comparative analysis of the fast implementations of Kruskal’s and Prim’s
algorithms, examining their effectiveness in different scenarios and graph types. The results aim
to provide insights into practical improvements and optimizations for MST algorithms,
contributing to their application in real-world problems and large-scale data sets.
CHAPTER III
METHODS

III.1 Implementation Details

Prim’s algorithm is a method for finding the minimum spanning tree (MST) of a connected,
undirected graph by determining an arbitrary vertex as a starting vertex of the MST, and gradually
adding the smallest edge that connects a vertex in the MST to the vertex outside the MST. To
efficiently implement Prim’s algorithm it utilized priority queues, such as binary heaps or fibonacci
heaps, to manage the vertices and their associated edge weights. Every time an edge is added,
the priority queue is updated to reflect the potential new edges.

Specifically, using a binary heap can reduce the time complexity of these operations,
bringing Prim's algorithm's overall complexity down to O(E log V), where E represents the number
of edges and V represents the number of vertices. Fibonnaci heaps can also offer better
performance by reducing time complexity to O(E + V log V). This is due to the Fibonacci heap's
ability to reduce key operations in constant time, thereby increasing the algorithm's
efficiency.Thus, incorporating priority queues such as binary or Fibonacci heaps into Prim's
algorithm significantly improves its efficiency. These changes reduce the algorithm's time
complexity, making it better suited for handling large graphs.

The traditional implementation of Prim's algorithm, which uses a simple array to store the
lowest edge weights, can be improved by replacing the array with a priority queue. This
adjustment allows for faster extraction of the minimum weight edge and more efficient vertex
weight updates. Additionally, the adjacency list or adjacency matrix graph representation and
linearly searching an array of weights.

Prim’s algorithm can be implemented in various programming languages, such as Python,


C++, or Java. For instance, in python imports a libraries like headq to handle priority queue, for
efficiently selecting the minimum weight edges in MST, initialize by choosing a starting vertex,
perform iteration, and continue the process until all vertices included in the MST.
Pseudocode:
T = ∅; U = { 1
}; while (U ≠
V)
let (u, v) be the lowest cost edge such that u ∈ U and v ∈ V - U;
T = T ∪ {(u, v)}
U = U ∪ {v}

III.2 Time Complexity: O(V^2)

Best-Case Scenario:
● Time Complexity: O(V^2)
● The Prim’s algorithm will still have to iterate through all V vertices and consider all
potential edges. This is because the algorithm lacks an efficient method for determining
which edges are guaranteed to be part of the minimum spanning tree without first
examining them.

● Overall time Complexity: O(V^2)

Average-Case Scenario:
● Time Complexity: O(V^2)
● The average-case scenario for Prim's algorithm is difficult to define precisely because it is
determined by the graph's edge weight distribution. However, in most practical scenarios,
the algorithm will still need to examine a significant portion of the edges, resulting in a
time complexity comparable to the worst-case.
● Overall time Complexity: O(V^2)

Worst-Case Scenario:
● Time Complexity: O(V^2)
● The worst-case scenario occurs when the graph is dense, which means that an edge
connects every pair of vertices. In this case, Prim's algorithm must examine all V * (V-1) /
2 edges. This yields a time complexity of O(V^2).
● Overall time Complexity: O(V^2)
CHAPTER IV
COMPARATIVE ANALYSIS

IV.1 Comparative Analysis for Prim’s Algorithm and Kruskal’s Algorithm

Category Prim’s Algorithm Kruskal’s Algorithm


Edge based: sorting all edges by
Vertex based: expand the MST weight and adding theme one by
by adding the smallest edges one
Approach
connected to the current MST
vertices

Data Structure
Uses priority queues Union-Find data structure
Graph
Representation Edge list
Adjacency matrix or adjacency
list

Suitable for dense graphs


Suitable graphs Suitable for sparse graphs
Time O (E log V) with priority queues O (E log E)
Complexity or O(V^2) for simple array

Additional memory usage for Less memory if edges can be


Memory Usage
priority queues sorted externally

IV.2 Results and Findings

Approach:

● Prim’s Algorithm: Expands the MST by adding the smallest edges connected to existing
vertices (vertex-based).
● Kruskal’s Algorithm: Sorts all edges by weight and adds them one by one to the MST (edge-
based).

Data Structure:

● Prim’s Algorithm: Utilizes priority queues for efficient edge selection.


● Kruskal’s Algorithm: Uses a Union-Find data structure to manage and merge sets.

Graph Representation:

● Prim’s Algorithm: Works with adjacency matrices or adjacency lists.


● Kruskal’s Algorithm: Uses an edge list.

Suitable Graphs:

● Prim’s Algorithm: More efficient for dense graphs.


● Kruskal’s Algorithm: More suitable for sparse graphs.

Time Complexity:

● Prim’s Algorithm: O(Elog V)O(E \log V)O(ElogV) with priority queues, or O(V2)O(V^2)O(V2)
with a simple array.
● Kruskal’s Algorithm: O(Elog E)O(E \log E)O(ElogE).

Memory Usage:

● Prim’s Algorithm: Requires additional memory for priority queues.


● Kruskal’s Algorithm: Less memory usage if edges are sorted externally.
CHAPTER V
CONCLUSION

V.1 Summary of findings

By consistently adding the lowest edge that joins a vertex inside the MST to one outside,
Prim's algorithm guarantees an optimal solution to the Minimum Spanning Tree (MST) issue. It is
a very effective method of addressing the problem. The choice of data structure has a big effect
on how efficient the method is; for example, the algorithm has a time complexity of O(ElogV)
when binary heaps or Fibonacci heaps are employed as priority queues. With thick graphs,
however, the temporal complexity of O(V ^2) when employing a basic array may be less effective.
Prim's Algorithm is best suited for applications like communication networks, circuit layouts, and
road networks that need to optimize local connection. It works best with dense graphs that have
a large number of edges in relation to vertices. Prim's Algorithm is a reliable and effective
technique for creating MSTs overall, and it may be made even more successful and economical
by choosing the right data structures.

V.2 Real-World Applications

1. Communication Network

● Prim’s algorithm can create efficient communication networks, such as

telecommunication and computer networks focusing on optimizing data packet


routing and minimizing total cost or distance between nodes, thereby ensuring
efficient and minimal delay in data transmission. Thus, it reduced installation cost,
improved data transmission efficiency, and reliable network connectivity.

2. Circuit Layout

● Prim's algorithm helps to reduce the length of interconnections between circuit

components in VLSI (Very-Large-Scale Integration) circuits. It lowers manufacturing


costs, lower power consumption, and smaller chip sizes all help to make
electronics faster and more efficient.

3. Image Processing

● Prim's algorithm can be used to segment images into regions based on similarity

measures, such as pixel intensity or color. Improving image clarity, object


recognition, and visual representation accuracy.

4. Clustering

● Prim's algorithm can be used to group similar data points into clusters, which is an

important step in data mining and machine learning. Improves the efficiency of
data classification, pattern recognition, and decision-making in artificial
intelligence and machine learning systems.

5. Railway Network

● Utilized Prim’s algorithm for efficient passenger and cargo transportation, reducing

travel time and cost. The use of this algorithm is to identify the shortest spanning
tree between stations, resulting in a network that promotes economic growth.

6. Social Network Optimization

● The use of Prim’s algorithm to create an optimized social network that enhances

communication, social capital, and efficiency by optimizing connections between


individuals. It will reduce communication time and improve individual well-being
by reducing the number of connections.

7. Medical Equipment Allocation

● Prim’s algorithm to optimize medical equipment allocation, ensuring efficient

healthcare delivery, cost reduction, and improved patient outcomes. The use of
the algorithm is to determine the shortest spanning tree connecting all healthcare
facilities, resulting in an efficient plan that reduces resource waste and improves
patient outcomes.

8. Optimal Road Construction

● Utilized Prim’s algorithm to develop a cost-effective road construction plan by


analyzing terrain, environment, and existing infrastructure. It will use linear
programming and optimization techniques to find the best route, resulting in a
cost-effective plan that meets community needs while minimizing environmental
impact.
REFERENCES

Aleem, M., Islam, M. A., Iqbal, M., & Mehmood, W. (2017). A Fast Implementation of Minimum
Spanning Tree Method and Applying it to Kruskal’s and Prim’s Algorithms.
https://www.semanticscholar.org/paper/A-Fast-Implementation-of-Minimum-Spanning-Tree-a
d-Munier-Aleem/ac19d0458b71773a9210e84dd29cffbc9735854d

Again, M. C. S. G. (2023, June 2). Prim’s Algorithm vs Kruskal’s Algorithm: Choosing the Right
Path to Minimum Spanning Trees. Medium.
https://medium.com/@MakeComputerScienceGreatAgain/prims-algorithm-vs-kruskal-s-algorit
hm-choosing-the-right-path-to-minimum-spanning-trees-d4d4cec8d687#:~:text=Prim%E2%80%
99s%20algorithm%20is%20efficient%20for%20dense%20graphs%20and,ensure%20the%20crea
tion%20of%20a%20minimum%20spanning%20tree.

GeeksforGeeks. (2024a, May 28). Prim’s Algorithm in Python. GeeksforGeeks.


https://www.geeksforgeeks.org/prims-algorithm-in-python/?ref=header_outind

GeeksforGeeks. (2024b, August 28). 10 Project Ideas That Use Prim’s Algorithm. GeeksforGeeks.
https://www.geeksforgeeks.org/project-ideas-that-use-prims-algorithm/

GeeksforGeeks. (2024b, July 14). Prim’s Algorithm for Minimum Spanning Tree (MST).
GeeksforGeeks. https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-
algo-5/

GeeksforGeeks. (2024c, July 17). Difference between Prim’s and Kruskal’s algorithm for MST.
GeeksforGeeks. https://www.geeksforgeeks.org/difference-between-prims-and-kruskals-
algorithm-for-mst/

Int. J. Comput. Sci. Trends Technol.(IJCST), 2018.”Review and Analysis of Minimum Spanning
Tree Using Prim's Algorithm”.
https://www.academia.edu/download/56204916/IJCST-V6I2P7.pdf

P. Ayegba, J. Ayoola, E. Asani and A. Okeyinka, "A Comparative Study Of Minimal Spanning Tree
Algorithms," 2020. A Comparative Study Of Minimal Spanning Tree Algorithms | IEEE
Conference Publication | IEEE Xplore
Wikipedia contributors. (2024, July 23). Prim’s algorithm. Wikipedia.
https://en.wikipedia.org/wiki/Prim%27s_algorithm#

You might also like