You are on page 1of 4

International Journal of Scientific Research Engineering & Technology (IJSRET) Volume 2 Issue3 pp 180-183 June2013 www.ijsret.

org ISSN 2278 0882

Review of Breadth First Search


Neeraj Goyat1, Madhu2 , Sunita3 (M.Tech.(Network Security) student- B.P.S Mahila Vishwavidhalaya, Khanpur Kalan,Sonepat,India) 2 (M.Tech.(Network Security) student- B.P.S Mahila Vishwavidhalaya, Khanpur Kalan,Sonepat,India) 3 (Assistant Professor, B.P.S Mahila Vishwavidhalaya, Khanpur Kalan,Sonepat,India)
1

Abstract In this, paper we have given an overview of breadth First Search .We have chosen a very simple and easy language to explain its example, procedure and pseudo code. BFS is one of the important Graph traversal techniques. BFS is based on queue data structure which follows FIFO structure. In graph theory, breadth-first search (BFS) is a graph search algorithm that begins at the root node and explores all the neighboring nodes. Then for each of those nearest nodes, it explores their unexplored neighbor nodes, and so on, until it finds the goal. Keywords - BFS, Breadth first Search, Traversal Algorithm, Graph traversal techniques, Queue Data structure I. INTRODUCTION

guaranteed to find the best possible solution in the non-weighted graph. Check each node nearest the root before descending to the next level. Uses a FIFO (first-in-first-out) queue. As new nodes found to be searched, these nodes are searched against the goal and if the goal is not found, new nodes are added to queue. Using FIFO order in new node search, we always check the oldest node first, resulting in breadth first review. For example V1

BFS is an uninformed search method that aims to expand and examine all nodes of a graph or combination of sequences by systematically searching through every solution. In other words, it exhaustively searches the entire graph or sequence without considering the goal until it finds it. It does not use a heuristic algorithm. From the standpoint of the algorithm; all child nodes obtained by expanding a node are added to a FIFO (i.e., First In, First Out) queue. In typical implementations, nodes that have not yet been examined for their neighbors are placed in some container (such as a queue or linked list) called "open" and then once examined are placed in the container "closed". II. PROCEDURE

V2

V3

V4

V5

V6

V7

In this method of graph traversal we visit the nodes breadth-wise until all the nodes are traversed. In graph, we do not have any start vertex therefore; traversing can start from any arbitrary vertex. After selecting and visiting start node its adjacent vertices selected. All the above vertices are selected in sequence. Then we can select and visit all the unvisited vertices of the above visited vertex and so on until all the nodes are visited. Procedure is Search the graph from the root node in order of the distance from the root. Order search is nearest to the root. BFS is

Steps:1.Let V1 be the start vertex. We visit the node. 2.The adjacent vertices are V2, V3. Suppose we visit V2, V3. 3.The adjacent to V2 are V1, V4, and V5. The V1 node is already visited. So visit node V4,V5. 4.The adjacent to V3 are V1, V6 and V7. The V1 is already visited. So visit node V6, V7. 5.The adjacent to V6 are V3 and V7. The V3 is already visited. So visit V7. The traversing sequence is V1, V2, V3, V4, V5, V6 and V7.

IJSRET @ 2013

International Journal of Scientific Research Engineering & Technology (IJSRET) Volume 2 Issue3 pp 180-183 June2013 www.ijsret.org ISSN 2278 0882

III.

BFS PSUEDOCODE

3.

The pseudo code for BFS is given below:1.Take an array queue [] for storing unvisited neighbor of the node. 2.Take a Boolean array Visited [] for storing visited status of the node that is it stores true for visited nodes and false for unvisited nodes. 3.Initially queue is empty i.e. rear=front= -1. 4.For I =1to n do Visited [] = false; 5.Insert starting node (vertex) into the stack. 6.Delete an element from the queue if it has not been traversed (visited) then visit it and set Visited [] true for the node. If it has already been traversed then just ignore it. 7.Now insert all the unvisited adjacent nodes of the deleted element in the queue. 8. Repeat steps 6 and 7 until the queue is empty. IV. EXAMPLE

Dequeue next vertex which is V2. And now visit neighbors of V2 which are V1 and V6. But V1 is already visited so, enqueue V6.

Front

V9 V6 FIFO Queue

Output: 4.

V1, V2 Dequeue V9 and visit neighbors of V9 which are V1, V5, V6. V1 is already visited and V6 is already in queue so enqueue V5.

Consider the following example:1. Initially the queue is empty. Starts with any arbitrary node, let say V1. So enqueue V1

Front

V6 V5 FIFO Queue

Front

V1 FIFO Queue

Output: 5.

V1, V2, V9 Dequeue V6 and visit neighbors of V6 which are V9, V5, V2, V7. V2, V9 are already visited so enqueue V5, V7. 2.

Output: 2. Dequeue V1 and Visit Neighbors of V1, which are V2 and V1. We are now finished with V1. Enqueue V9 and V2.

Front Front V2 V9 FIFO Queue Output: V1 6.

V5 V7 FIFO Queue

Output:

V1, V2, V9, V6 Dequeue V5 and visit neighbors of V5 which are V9, V6. V6, V9 are already visited .

IJSRET @ 2013

International Journal of Scientific Research Engineering & Technology (IJSRET) Volume 2 Issue3 pp 180-183 June2013 www.ijsret.org ISSN 2278 0882

Front

V7 FIFO Queue

Output: 7. Dequeue V7 and visit neighbors of V7 which are V3, V8, V6. V6 is already visited, so enqueue V5, V7.

V1, V2, V9, V6, V5

Output:

V1, V2, V9, V6, V5, V7, V3, V8

10. Dequeue V4 and visit neighbor of V4 which is V3 and it is already visited.

Front

V3 V8 FIFO Queue

Output: 8.

V1, V2, V9, V6, V5, V7 Front Dequeue V3 and visit neighbors of V3 which are V4, V7. V7 are already visited so enqueue V4. FIFO Queue Output: V1,V2,V9,V6,V5,V7,V3,V8,V4 vkmjhVV8,V4 V. ADVANTAGES

Following are the advantages: No dead end BFS has no dead end hence, there is no need of backtracking. Complete and Optimum. Front V8 V4 FIFO Queue Output: 9. V1, V2, V9, V6, V5, V7, V3 Dequeue V8 and visit neighbors of V8 which are V3, V7. V7, V3 are already visited. VI. DISADVANTAGES

Following are the disadvantages: Time Consuming Time will be required for the operations of enqueuing and dequeuing as well as for scanning the adjacency list of each vertex. Memory Consuming. VII. ANALYSIS Time Complexity:The operations of enqueuing and dequeuing take O(1) time, so the total time devoted to key operations is O(V). Because the adjacency list of each vertex is scanned only when the vertex is dequeued each adjacency list is scanned at most once. Since the sum of the lengths of all the adjacency list is Q(E), total time spent is scanning adjacency list is O(E). The overhead for initialization is O(V), and thus total running time of BFS is

Front

V4 FIFO Queue

IJSRET @ 2013

International Journal of Scientific Research Engineering & Technology (IJSRET) Volume 2 Issue3 pp 180-183 June2013 www.ijsret.org ISSN 2278 0882

O(V+E). Thus, BFS runs in linear time in the size of the adjacency-list representation of G. Space Complexity:The space complexity can be expressed as where is the cardinality of the set of vertices. If the graph is represented by an Adjacency list it occupies space in memory, while an Adjacency matrix representation occupies. VIII. REFRENCES [1]. Thomas H. Cormen, Design and Analysis of Algorithms, 2nd Edition [2].http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_ key_exchange [3]. http://www.youtube.com/watch?v=QRq6p9s8NVg [4]. http://www.youtube.com/watch?v=qBfzDxihJz4

IJSRET @ 2013

You might also like