This preview shows page 1. Sign up to view the full content.
Unformatted text preview: repeat the process. 5.Repeat above steps until all nodes have not been covered. Running Time AnalysisBredthFirst SearchIn 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). DepthFirst SearchThe 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.
 Spring '10
 narayanaswamy

Click to edit the document details