# `

Graph is another important non-linear data structure. In a tree structure, there is a hierarchical relationship between parent and children, that is, one parent and many children. On other hand, in graph, relationship is less restricted. Here relationship is from many parents to many children. Graph structure can be seen everywhere in the real world. Some examples are given below so as to understand this structure better.

`



Airlines Flowchart of a program



GRAPH ` A graph G= (V.E) consist of a finite non empty set of vertices V also called pointes or nodes and a finite set E of unordered pairs of distinct vertices called edges and arcs or links. Basic Terminologies ` ` ` ` ` ` Weighted graph Diagraph Adjacent vertices Self loop Parallel edges Simple graph ` ` ` ` ` Complete graph Acyclic graph Isolated vertex Degree of vertex Connected graph .

. two methods are known to be very efficient : Kruhskal¶s algorithm Prim¶s algorithm. Out of them . There are several methods available for finding a minimum spanning tree of a graph.` ` A minimum spanning tree (MST) or minimum weight spanning tree is then a spanning tree with weight less than or equal to the weight of every other spanning tree.

Select the shortest edge in a network Select the next shortest edge which does not create a cycle 3. 1. Repeat step 2 until all vertices have been connected 4. Prim¶s algorithm Select any vertex Select the shortest edge connected to that vertex Select the shortest edge connected to any vertex already connected Repeat step 3 until all vertices have been connected . 3.Minimum Connector Algorithms Krushkal¶s algorithm 1. 2. 2.

Select all smallest edge from the list and add in into the spanning tree (initially is a empty) if the inclusion of this edges does not make a cycle If the selected edge with smallest weight forms a cycle. This algorithm can then be informally stated as follows: ` ` ` ` ` List all the edges of the graph G in the increasing order of weights.Let us assume an undirected weighted graph with n vertices.else return the minimum spanning tree T. where initially the spanning tree is empty. Repeat steps 2-3 until the tree contains n-1 edge or list is empty. . remove it from the list. If the tree T contains less than n-1 edges and the list is empty . no spanning tree is possible for the graph .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 List the edges in order of their size: BP CF AP BD PD AB PF AC FE PE PC DE 1 1 2 2 3 4 4 5 6 7 8 9 1 .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 Select the shortest edge in the network: BP 1(or CF 1) 1 .

A Select the next shortest edge which does not create a cycle: C B 1 2 3 D 7 9 E 6 F P BP CF 1 1 1 .

A 4 B 2 1 2 P 4 D 7 9 E 6 F 8 C 5 Select the next shortest edge which does not create a cycle: BP CF BD 1 1 1 2(or AP 2) .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 Select the next shortest edge which does not create a cycle: BP CF BD AP 1 1 1 2 2 .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 Select the next shortest edge which does not create a cycle: BP CF BD AP BC AB PF 1 1 2 2 3 4 4 1 forms a cycle forms a cycle .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 Select the next shortest edge which does not create a cycle: BP CF BD AP BC AB PF AC EF 1 1 2 2 3 4 4 5 6 1 forms a cycle forms a cycle forms a cycle .

A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 Select the next shortest edge which does not create a cycle: BP CF BD AP BC AB PF AC EF PE PC DE 1 1 2 2 3 4 4 5 6 7 8 9 1 forms a cycle forms a cycle forms a cycle forms a cycle forms a cycle forms a cycle .

The solution is: BP CF BD AP PF EF 1 1 2 2 4 6 1 Total weight of tree is: 16 .A 4 B 2 1 2 3 D 7 9 E 6 P 4 F 8 C 5 All the vertices have been connected.

Program using graphics Program without graphics .