Skip to main content

Discrete Mathematical Structures

 

UNIT-3

Prim's Algorithm

Prim's Algorithm is used to find the minimum spanning tree from a graph. 

Spanning tree : A tree T is said to be spanning tree if  it contains all the vertices and do not form any cycles. i.e.  without forming any cycles a tree can be constructed and must have all the vertices. 

Prim's algorithm finds the subset of edges that includes every vertex of the graph such that the sum of the weights of the edges can be minimized.

Prim's algorithm starts with the single node and explore all the adjacent nodes with all the connecting edges at every step. The edges with the minimal weights causing no cycles in the graph got selected.

The algorithm is given as follows.

Algorithm

  • Step 1: Select a starting vertex
  • Step 2: Repeat Steps 3 and 4 until there are fringe vertices
  • Step 3: Select an edge e connecting the tree vertex and fringe vertex that has minimum weight
  • Step 4: Add the selected edge and the vertex to the minimum spanning tree T
    [LOOP ENDS]
  • Step 5: EXIT

Example :

Construct a minimum spanning tree of the graph given in the following figure by using prim's algorithm.


Step 1 : Choose a starting vertex B.
Step 2: Add the vertices that are adjacent to A. the edges that connecting the vertices are shown by dotted lines.
Step 3: Choose the edge with the minimum weight among all. i.e. BD and add it to MST. Add the adjacent vertices of D i.e. C and E.
Step 3: Choose the edge with the minimum weight among all. In this case, the edges DE and CD are such edges. Add them to MST and explore the adjacent of C i.e. E and A.
Step 4: Choose the edge with the minimum weight i.e. CA. We can't choose CE as it would cause cycle in the graph.
The graph produces in the step 4 is the minimum spanning tree of the graph shown in the above figure.
The cost of MST will be calculated as;
cost(MST) = 4 + 2 + 1 + 3 = 10 units.








Comments

Popular posts from this blog

Advanced Structural Modeling

                                                                      Unit II                                                     Advanced Structural Modeling  A relationship is a connection among things. In object-oriented modeling, the four most important relationships are dependencies, generalizations, associations, and realizations.  Graphically, a relationship is rendered as a path, with different kinds of lines used to distinguish the different relationships. Dependency A dependency is a using relationship, specifying that a change in the specification of one thing may affect another thing that uses it, but not necessarily the reverse. Graphically, a dependency is rendered as a dashed line  A plain, unadorned dependency relationship is sufficient for most of the using relationships you'll encounter. However, if you want to specify a shade of meaning, the UML defines a number of stereotypes that may be applied to dependency relationships. There are 17 such stereo

Design Patterns UNIT-2

 A Case Study: Design a Document Editor ¾     This chapter presents a case study in the design of a "What-You-See-Is-What-You-Get" (or "WYSIWYG") document editor called Lexi. ¾     We'll see how design patterns capture solutions to design problems in Lexi. ¾     A WYSIWYG representation of the document occupies the large rectangular area in the center. ¾     The document can mix text and graphics freely in a variety of formatting styles. ¾     Surrounding the document are the usual pull-down menus and scroll bars, and a collection of page icons for jumping to a particular page in the document.    Design Problems: Seven problems in Lexis's design: Document Structure: The choice of internal representation for the document affects nearly every aspect of Lexis's design.    All editing, formatting, displaying, and textual analysis will require traversing the representation.   The way we organize those impacts design information.

Artificial Intelligence

  Chapter 1                                                                                                                                 ( Source: Google) Intelligence What is “Intelligence”? -- Everyone has his own definition but no one has a precise one at that -- Everyone agrees that humans and dogs are intelligent, trees are not What is AI? Two dimensions: 1.Thought processes and reasoning (internal) 2.Behavior (external) Two factors for measuring success along each dimension: 1.Success in terms of fidelity to human performance 2.Success in terms of an ideal performance measure, called rationality. Acting humanly: Turing Test •Turing Test -- Proposed by Alan Turing in 1950 -- Designed to provide a satisfactory operational definition of intelligence -- A computer passes the test if a human interrogator, after posing some written questions, cannot tell whether the written responses come from a person or from a computer -- No physical interaction between the interrogator and the c