Document 1 - repeat the process 5.Repeat above steps until all nodes have not been covered Running Time Analysis-Bredth-First Search-In BFS each

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Description of algorithms --------------------------- Bredth-First Search -------------------- 1.Mark all the vertices as unvisited 2.Enter the head node in the queue. 3.Until the queue is not empty do the following: a.Remove a node from the queue. b.If the node is not yet been visited, marks as visited. c.Insert all the adjacent nodes of the current node in the queue. 4.If graph is disconnected, find out the vertex which has not been covered and repeat the process. 5.Repeat above steps until all nodes have not been covered. Depth-First Search ------------------- 1.Mark all vertices as unvisited. 2.Push head node in the main stack. 3.Until the stack is not empty do the following: a.Push all the unvisited adjacent nodes in a unvisited stack. b.If there are no unvisited adjacent nodes then pop node from main stack. c.Else pop a node from unvisited stack. d.If node is not visited then mark as visited. 4.If graph is disconnected, find out the vertex which has not been covered and
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: repeat the process. 5.Repeat above steps until all nodes have not been covered. Running Time Analysis----------------------Bredth-First Search--------------------In BFS each vertex is enqueued only once. So it will be also dequeued once.The operations of enqueuing and dequeuing take O(1) time, so the total time consumed queue operations is O(V). Because the adjacency list of each vertex is scanned only when the vertex is dequeued, the adjacency list of each vertex is scanned at most once. Since the sum of the lengths of all the adjacency lists is Q(E), at most O(E) time is spent in total scanning adjacency lists. The overhead for initialization is O(V), and thus the total running time of BFS is O(V + E). Depth-First Search-------------------The loop in DFS takes O(V) time. DFS function is called once for every vertex. The cost of executing the adjacency for every vertex is Theta(E). Thus the resulting complexity of DFS wii be O(V + E)....
View Full Document

This note was uploaded on 09/08/2010 for the course COMPUTERSC cs5800 taught by Professor Narayanaswamy during the Spring '10 term at Indian Institute of Technology, Chennai.

Ask a homework question - tutors are online