Algorithms for Generating Star and Path of Graphs Using BFS Dr
Total Page:16
File Type:pdf, Size:1020Kb
Web Site: www.ijettcs.org Email: [email protected], [email protected] Volume 1, Issue 3, September – October 2012 ISSN 2278-6856 Algorithms for Generating Star 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 vertex 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 polyhedral graph on four nodes which is also the A graph is a finite collection of objects called vertices complete graph and therefore also the wheel graph . 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 Cycle Graph: 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.