answersLogoWhite

0

Algorithm's don't have source code per se. Source code depends on the programming language used to implement the algorithm and this will obviously vary from language to language. However, we often use pseudo-code to provide an informal language-agnostic implementation in human-readable form. Pseudo-code is not source code because it is not machine-readable and has no formal standard. However, it employs established structured programming conventions such as loops and variables, thus the code can be easily adapted to suit many high-level programming languages.

Prim's algorithm can be informally described as follows:

  1. Initialise a tree with a single vertex, chosen arbitrarily from the graph.
  2. Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree.
  3. Repeat step 2 until all vertices are in the tree.

In pseudo-code, the algorithm can be implemented as follows:

Associate with each vertex v of the graph a number C[v] (the cheapest cost of a connection to v) and an edge E[v] (the edge providing that cheapest connection). To initialise these values, set all values of C[v] to +∞ (or to any number larger than the maximum edge weight) and set each E[v] to a special flag value indicating that there is no edge connecting v to earlier vertices.

Initialise an empty forest F and a set Q of vertices that have not yet been included in F (initially, all vertices).

Repeat the following steps until Q is empty:

  1. Find and remove a vertex v from Q having the minimum possible value of C[v]
  2. Add v to F and, if E[v] is not the special flag value, also add E[v] to F
  3. Loop over the edges vw connecting v to other vertices w. For each such edge, if w still belongs to Q and vw has smaller weight than C[w], perform the following steps:
  • Set C[w] to the cost of edge vw
  • Set E[w] to point to edge vw

Return F

Source: wikipedia

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

Can someone provide the C program for Prim's algorithm?

The C code for Prim's algorithm can be found in the following link. https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-find-minimal-spanning-tree-using--prims-algorithm


Where do you get the exact source code in C that implements lossless compression algorithm?

The source code, in C, will depend on what type of lossless compression algorithm will be used. A source code should be available from various computer scientists in your area.


How do i get source code for bide algoritham?

You can get the Java source code for the BIDE data mining algorithm here : (link moved to link section) It is an open-source data mining framework that includes the BIDE algorithm


Java source code for median filter algorithm?

research is going on to develop a source code for median filtering using java


What is the difference of source code object code and pseudo code?

Source code is a sequence of executable instructions written in a particular language. Pseudo code is a sequence of non-executable instructions. It is also called algorithm written in plain English


Source code Thomas algorithm to solve trichagonal system of finite difference method?

Visit related link below for coding in C,Matlab, Fortran


What is the source of a website?

Do you mean source code? If so, the source code is the actual code a person or program writes up to makes a webpage/site display and function in the desired fashion. It can often be found by right clicking on a webpage and selecting "View Source code"


What is the code of pegasis?

PEGASIS Cluster Algorithm Code for WSN Omnet++ ?


What is A algorithm in AI?

A algorithm in artificial intelligence is a line of code meant to simulate a human emotion.


What is pseudo code algorithm for create a linked list with a header and insert a four numbers to the list?

pseudo code algorithm to create a linked list


Are algorithms only meant for computers?

No. Indeed, algorithms are actually meant for humans, not computers. Computer programmers translate algorithms into working code such that a computer can process the algorithm. The code is actually the implementation of the algorithm, not the algorithm itself.


How could you view the code written on a webpage?

In Internet Explorer, you can 'View Source'. This is found by clicking view > source.