Prism Algorithm in Data Structure

Prism Algorithm is a type of greedy algorithm so finding the minimum spanning tree in this algorithm should have the property that edges in a set ($\pi$) always from a single tree that is a tree stats from arbitrary root vertex (R) and grows until the tree spans all the vertices (V).

Algorithm With Explanation

  1. for each u $\epsilon$ v[G]
  2. do key [u] $\gets \infty$
  3. $\pi$[u] $\gets$ NIL
  4. key [r] $\gets \phi $
  5. Q $ \gets $ v[G]
  6. while Q $\neq \phi $
  7. do u $\gets$ EXTRACT_MIN(Q)
  8. for each v $\epsilon$ adjacent [u]
  9. do if V $\epsilon$ Q and w(u,v) < key[v]
  10. then $\pi$ [ v] $\gets$ u
  11. key [v] $\gets$ w(u,v)
  1. In this algorithm lines 1-5 set the key of each vertex to $\infty$, the parent of each u to NIL and the priority queue Q to certain all the vertices.
  2. In lines 6-7, it identifies the vertex
  3. In lines 8-11 for loop updates the key and $\pi$ field by every vertex [v] adjacent to u but not in the tree.

Prism Algorithm Based Problem with solution

Problem:

Solution:

Initialize all the vertex to infinity and the root vertex as 0

ABCDEFGHIJ
0$\infty$$\infty$$\infty$$\infty$$\infty$$\infty$$\infty$$\infty$$\infty$

Now visit vertex A and connect vertex B and D then the value of vertices will be as shown since AB = 4 and AD = 1 as given in the problem

ABCDEFGHIJ
04A$\infty$1A$\infty$$\infty$$\infty$$\infty$$\infty$$\infty$

After this, the minimum span is between A and D.So, the solution will be

Now visit vertex D since AD is small than AB So, we will visit vertex D and its connecting vertex AD = 1, BD = 4, HD = 4, JD=4 as given in the problem

ABCDEFGHIJ
04D$\infty$1A$\infty$$\infty$$\infty$5D$\infty$6D

After this, the minimum span is between D and B. So, the solution will be

Now visit vertex B since DB is smaller. So, we will visit vertex B and its connecting vertex AB = 4, DB =4, JB=7, CB = 4

ABCDEFGHIJ
04D4B1A$\infty$$\infty$$\infty$5D$\infty$6D

After this, the minimum span is between C and B. So, the solution will be

Prism Algorithm

Now visit vertex C since CB is smaller. So, we will visit vertex C and its connecting vertex EC = 2, FC =1, CB = 4

ABCDEFGHIJ
04D4B1A2C1C$\infty$5D$\infty$6D

After this, the minimum span is between F and C. So, the solution will be

Now visit vertex F since FC is smaller. So, we will visit vertex F and its connecting vertex CF =1, GF = 3, IF = 5

ABCDEFGHIJ
04D4B1A2C1C3F5D5F6D

After this, the minimum span is between G and F. So, the solution will be

Now visit vertex G since FG is smaller. So, we will visit G and its connecting vertex EG=2, FG=3, IG=3, JG=4

ABCDEFGHIJ
04D4B1A2G1C3F5D3G4G

After this, the minimum span is between E and G. So, the solution will be

Now visit vertex E since EG is smaller. So, we will visit vertex E and its connecting vertex EC = 2, EG = 2. But its connecting vertex is already visited so we visit vertex I since IG is second smaller and its connecting vertex IG = 3, IJ = 3

ABCDEFGHIJ
04D4B1A2G1C3F5D3G3I

After this, the minimum span is between F and G . So, the solution will be

Now visit vertex J since IJ is smaller. So, we will visit vertex J and its connecting vertex JD = 6, JB =7, JG=4, JH=2, JI = 3

ABCDEFGHIJ
04D4B1A2G1C3F2J3G3I

After this, the minimum span is between IJ. So, the solution will we

Now we finally visit the final vertex H as HJ = 2. So, the solution to the problem will be:


Discover more from easytechnotes

Subscribe to get the latest posts sent to your email.

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to Top