Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: DSA - Prims
Description: This notes is for Prims algorithm used to find the minimum spanning tree in the given graph. It has the explanation, code and example for the algorithm. It also has time complexity, advantages, disadvantages and applications.
Description: This notes is for Prims algorithm used to find the minimum spanning tree in the given graph. It has the explanation, code and example for the algorithm. It also has time complexity, advantages, disadvantages and applications.
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
Prims Algorithm - Greedy Method
Explanation
Prim's algorithm is a greedy algorithm that finds the minimum spanning tree of a weighted,
undirected graph
...
Prim's algorithm works by starting with a single vertex and then growing the tree by adding the
edge with the minimum weight that connects the tree to a new vertex
...
Algorithm
1
...
2
...
Add the edge to the minimum spanning tree
...
3
...
Code
Here is an implementation of Prim's algorithm in Python:
Python
def prims(graph):
mst = set([graph[0]])
visited = set([graph[0]])
while len(visited) < len(graph):
current = min(
(v for v in visited if v not in mst),
key=lambda v: min(weight for u, weight in graph[v]
...
add(current)
visited
...
items():
if neighbor not in visited and weight < min(
edge[1] for edge in mst if edge[0] == current):
mst
...
The algorithm starts with the vertex A and then adds the edge with the minimum weight, which
is the edge from A to B with weight 2
...
The minimum spanning tree of
this graph is the tree with edges AB, BC, and CD
...
This is because the algorithm needs to sort
the edges in the graph at each step, which takes O(E log V) time
...
It is also a greedy algorithm, which means that it always finds a feasible solution to the
problem
...
This is because the
algorithm needs to sort the edges in the graph at each step
...
If the graph is not connected, then the algorithm will not terminate
...
Finding the minimum cost of connecting a set of cities with flights
...
Prim's algorithm is also used in a variety of other applications, such as:
Natural language processing
Robotics
Operations research
Title: DSA - Prims
Description: This notes is for Prims algorithm used to find the minimum spanning tree in the given graph. It has the explanation, code and example for the algorithm. It also has time complexity, advantages, disadvantages and applications.
Description: This notes is for Prims algorithm used to find the minimum spanning tree in the given graph. It has the explanation, code and example for the algorithm. It also has time complexity, advantages, disadvantages and applications.