For DFS, this is proportional to the length of the path from the root to the node currently being visited. For disconnected graph, Iterate through all the vertices, during iteration, at a time consider each vertex as source (if not already visited). During execution, the BFS and DFS algorithms maintain an amount of state proportional to the size of the queue or stack.Observe closely the previous step, it will ensure that vertex will be pushed to stack only when all of its adjacent vertices (descendants) are pushed into stack. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |