Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

Algorithms for Generating and Path of Graphs using BFS Dr. H. B. Walikar2, Ravikumar H. Roogi1, Shreedevi V. Shindhe3, Ishwar. B4 2,4Prof. Dept of Computer Science, Karnatak University, Dharwad, 1,3Research Scholars, Dept of Computer Science, Karnatak University, Dharwad

Abstract: In this paper we deal with BFS algorithm by 1.8 Diamond Graph: modifying it with some conditions and proper labeling of The diamond graph is the simple graph on nodes and vertices which results edges illustrated Fig.7. [2] and on applying it to some small basic 1.9 Paw Graph: class of graphs. The BFS algorithm has to modify The paw graph is the -pan graph, which is also accordingly. Some graphs will result in and by direct application of BFS where some need modifications isomorphic to the -tadpole graph. Fig.8 [2] in the algorithm. The BFS algorithm starts with a root 1.10 Gem Graph: called start vertex. The resulted output tree structure will be The gem graph is the fan graph illustrated Fig.9 [2] in the form of Structure or in Structure. 1.11 Dart Graph: Keywords: BFS, Graph, Star, Path. The dart graph is the -vertex graph illustrated Fig.10.[2] 1.12 Tetrahedral Graph: 1. INTRODUCTION The tetrahedral graph is the Platonic graph that is the 1.1 Graph: unique on four nodes which is also the A graph is a finite collection of objects called vertices and therefore also the . together with a set of unordered pairs of distinct vertices Fig.11 [2] of , called edges. The vertex set and the edge set of 1.13 Concatenation: are denoted by and respectively. A graph The act of linking together as in a series or chain. with vertex set and edge set is denoted 1.14 Concatenation Graph : by . [1] A Cycle and Path class of graph linked together as in a 1.2 Star Graph: series as shown Fig.12. The Star graph of order , sometimes simply known as 1.15 Breadth First Search Algorithm (BFS): an " -star", is a tree on -nodes with one node having Breadth first search is another useful tool in many graph vertex degree and the other having vertex algorithms. The BFS visits systematically the vertices of degree . Fig.1 [2] graph or digraph, beginning at some vertex of (also 1.3 Path Graph: called a root vertex). The root vertex is the first active The Path is a tree with two nodes of vertex degree , vertex. At any stage during the search, all the vertices and the other nodes of vertex degree . A path adjacent from the current active vertex are scanned for graph is a graph that can be drawn so that all of its vertices that have not yet been visited that are “broad” vertices and edges lie on a single straight line. Fig.2 [2] search performed for unvisited vertices. Each time a 1.4 : vertex is visited for the first time, it is labeled (according A cycle graph , sometimes simply known as an -cycle, to some rule that depends on the goal to be achieved) and is a graph on -nodes containing a single cycle through added back to the queue. Note that, in this search a queue all nodes. Fig.3 [2] is used rather than a stack. The current active vertex is 1.5 Complete Graph: the one at the front of the queue. As soon as its neighbors A complete graph is a graph in which each pair of graph have been visited, it is deleted from the queue. If the vertices is connected by an edge. The complete graph queue is empty and some vertices of the graph or with graph vertices is denoted . Fig.4 [2] diagraph have not yet been visited, we select any 1.6 Wheel Graph: unvisited vertex, assign it a label and add it to the queue. A wheel graph of order , sometimes simply called an When all the vertices of the graph have been visited, the -wheel, is a graph that contains a cycle of order , search is complete. [3] and for which every graph vertex in the cycle is connected Applications: to one other graph vertex. Fig.5 [2] 1. Finds a tree. 1.7 Windmill Graph: 2. Tests cross edge connectivity. The windmill graph is the graph obtained by taking 3. Find paths. 4. Find cyclicity. copies of the complete graph with a vertex in 1.16 Queue: common. Fig.6 [2]

Volume 1, Issue 3, September – October 2012 Page 117

Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

A queue is a list of elements which supports the following operations enqueue: Adds an element to the end of the list dequeue: Removes an element from the front of the list Fig. 5: Wheel Elements are extracted in first-in first-out (FIFO) order, i.e., elements are picked in the order in which they were inserted. [4] 1.17 Algorithm BFS (v): [5] // Implements a breathe-first search traversal of a given Fig. 6: Windmill graph // Input: Graph // Output: Graph with its vertices marked with consecutive integers // in the order they have been visited by the BFS traversal mark each vertex in with as a mark of being “unvisited” Fig. 7: Diamond for each vertex in do if is marked with

bfs (v) bfs (v) // visits all the vertices connected to root v by a path // assigns them the numbers in the order they are visited // via global variable count ; mark with count and Fig. 8: Paw initialize a queue with . while the queue is not empty do for each vertex in adjacent to the front vertex do if is marked with ; mark with count Fig. 9: Gem add to the queue remove the front vertex from the queue.

Fig. 1: Star . Fig. 10: Dart

Fig. 2: Path

Fig. 11: Tetrahedral Fig. 3: Cycle

Fig. 4: Complete Fig. 12: Concatenation Graph

Volume 1, Issue 3, September – October 2012 Page 118

Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

2. PROPOSED WORK: : Our aim is to find the small class of graphs which can For the given graph in fig.13, if we apply BFS with vertex result in BFS tree which is star graph called BFS Star as a start vertex, then we get as described and BFS tree which is path called BFS Path , after below application of BFS. i.e. and .

Some graphs will result in Star and Path by direct application of BFS where some need modifications in the algorithm. The BFS algorithm starts with a root vertex called start vertex. The resulted output tree will be in the form of Star or in Path .

In this paper we are dealing with some small basic graphs and their behavior on applying BFS. Some of the graph Fig. 15 with start vertex classes results in and Therefore the is in the form of Path after applying some conditions and In the same way if we take as a start vertex then we get by specifying start vertex and modifying the BFS result as . algorithm accordingly. We want to generate a Star This example clearly shows that same graph has different and Path by applying BFS on the given graph. We first structures, taking different start vertex which is show some class of graphs which results in Star as well as Path . Just we have to identify the and then will show some class of start vertex which is done by modifying BFS algorithm. graphs which results in by finding the Another class of graph i.e. Diamond graph which gives both and . start vertex by modifying BFS algorithm. To elaborate the concept let us consider the following example.

Paw Graph which results both and .

3. GRAPH CLASSES THAT GIVES BFS STAR ,

BY APPLYING BFS WITHOUT ANY CONDITIONS:

3.1. Star graph: When is star, then applying BFS by taking any vertex as a start vertex it gives . Here each vertex is a start vertex.

3.2. Complete graph: In complete graph also each vertex is start vertex. When Fig. 13 is complete, then applying BFS with taking any vertex as start vertex it gives 3.3. Tetrahedral Graph: : When is Tetrahedral, then applying BFS by taking any For the given graph, in Fig.13 if we apply BFS with vertex as start vertex it gives . Here also each vertex as start vertex, then we get as in Fig. vertex is start vertex. 14.

1 4. GRAPH CLASSES THAT GIVE BFS STAR ( )

BY SPECIFYING A START VERTEX:

Algorithm BFS Star by BFS (G)

// I/P: Graph .

// O/P: Star Graph in the order they have been visited by BFS traversal. Fig. 14 with start vertex Step 1: Find the degree of vertices and find the max deg of a Graph. Step 2: Let the start vertex ‘S’ be the vertex with max

deg . Therefore the structure of is in the form of Step 3: Apply BFS on given graph with ‘S’ as start Star . vertex.

Step 4: We get the output as a BFS Star .

Volume 1, Issue 3, September – October 2012 Page 119

Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

In this section we will study about how the start vertex ‘ ’ of given graph is obtained so that vertices are visited in a specific order from start vertex. For some class of graphs Start we can obtain by specifying start vertex and applying BFS algorithm accordingly. In the same way we show certain class of graph which results . Consider below example. Graph Consider Dart graph as shown in fig.16:

initialize adjacent matrix

FDM()

Fig.16 BFS (G) The degree of each vertex is:

BFS Star

In this graph we have and and degree also Therefore is a vertex with max degree . Let Stop be a start vertex. Applying to fig.16, let be start vertex: Fig.18 Flow Chart of Algorithm BFS Star by BFS (G)

FDM ()

for

Fig.17 with start vertex Therefore Dart graph in Fig.17. Assign max degree

Therefore the class of graphs which results are Wheel graph,

Windmill graph and Gem graph.

Return max node

5. GRAPH CLASSES THAT GIVES BFS PATH , BY APPLYING BFS WITHOUT ANY CONDITIONS: 5.1 Cycle:

Volume 1, Issue 3, September – October 2012 Page 120

Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

When is cycle , then by applying the BFS simply gives a . Of course the cycle results in just by removing the edge also. But here we are studying with respect to BFS. In cycle every vertex is a start vertex.

5.2 Path: By applying BFS on any path graph , we get it as a result. Here every vertex is a start vertex.

6. GRAPH CLASSES THAT GIVE BFS PATH ( ) BY SPECIFYING A START VERTEX: Fig.21 Algorithm BFS Path by BFS (G) Therefore . // I/P: Graph . // O/P: Path Graph in the order they have been visited by BFS traversal. Step 1: Find the diameter of cycle which is . Step 2: Find a vertex ‘ ’ which is at a from the concatenated vertex of . Step 3: Select as a start vertex. Step 4: Apply BFS using ‘ ’ as start vertex. Step 5: We get output . In this section we will study about how the start vertex ‘ ’ of given graph is obtained so that vertices are visited in a specific order from start vertex. For concatenated graph class of graphs we can obtain by specifying start vertex and applying BFS algorithm accordingly. Here if cycle is even we get one start vertex, if odd we get two start vertex we can take any one of them as a start vertex. Consider a graph as shown Fig.20

Fig.20 According to our modified algorithm applying on above graph, in which first step we find the diameter of

c = concatenated vertex Therefore d =diameter of cycle Here concatenated vertex of of given graph is . In second step we find vertex from vertex at . 7. CONCLUSION: i.e. . Therefore here the vertex is . In By using a BFS, here we are finding a Star consisting third step here we take as a start vertex any one of all the vertices of the given graph and the Path them. In step four we apply BFS to start vertex, consider consisting all the vertices of the given graph. Only few as a start vertex. classes of graphs have been tested here. We can consider Applying to fig.20, let be start vertex:

Volume 1, Issue 3, September – October 2012 Page 121

Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856

some more class of graphs for further analysis like House graph, Bull Graph.

REFERENCES:

[1] H. B. Walikar, Shreedevi. V Shindhe, Ravikumr

H.Roogi, I.Baidari, “Algorithms for a Path

generated by DFS”, IJCST, Vol. 3, Issue. 8, Aug

2012.

[2] http:// math world. Wolfram.com.

[3] Gray Chart and Ortrud R. Oellermann, “Applied

and Algorithmic ”.

[4] CS 473. “Fundamental Algorithms”, Spring 2011.

[5] Anany Levitin, “Introduction to the Design and

Analysis of Algorithms.”

[6] Harary. F, Graph Theory, Addison Wesley.

[7] Cormen, Thomas H.; Leiserson, Charles E.;

Rivest, Ronald L.; Stein, Clifford (2001). "Section

24.3: Dijkstra's algorithm". Introduction to

Algorithms (Second ed.). MIT Press and McGraw-

Hill. pp. 595–601. ISBN 0-262-03293-7.

AUTHOR

Ravikumar H. Roogi received the B.Sc (Electronics). and M.Sc(Computer Science). degrees from Karnatak University Dharwad in 2006 and 2008, respectively. Currently pursuing PhD (Computer Science) under guidance of Dr. H. B. Walikar from Karnatak University Dharwad.

Volume 1, Issue 3, September – October 2012 Page 122