Traversal of a graph is different from tree becausea)BFS of a graph uses queue, but a time efficient BFS of a tree is recursiveb)DFS of a graph uses stack, but inorder traversal of a tree is recursivec)All of the mentionedd)There can be a loop in graph so we must maintain a visited flag for every vertex
Question
Traversal of a graph is different from tree becausea)BFS of a graph uses queue, but a time efficient BFS of a tree is recursiveb)DFS of a graph uses stack, but inorder traversal of a tree is recursivec)All of the mentionedd)There can be a loop in graph so we must maintain a visited flag for every vertex
Solution
The traversal of a graph is different from a tree due to the following reasons:
a) Breadth-First Search (BFS) of a graph uses a queue data structure. This is because BFS explores all the vertices of a graph at the current level (i.e., breadth) before moving on to the vertices at the next level. However, a time-efficient BFS of a tree is recursive, which means it uses a call stack (not to be confused with a stack data structure).
b) Depth-First Search (DFS) of a graph uses a stack data structure. This is because DFS explores a path as far as possible (i.e., depth) before backtracking. But, an inorder traversal of a tree is recursive, which means it uses a call stack.
c) All of the mentioned points are correct.
d) There can be a loop in a graph, so we must maintain a visited flag for every vertex to avoid getting stuck in an infinite loop. This is not necessary in a tree because trees are acyclic by definition, which means they do not contain any loops.
Similar Questions
You7. Graph traversal is different from a tree traversal, because….a. trees are not connectedb. graphs may have loopsc. trees have rootd. None of these
The BFS search traversal of a graph will result into?a)Linked listb)Stackc)Treed)Queue
Which of the following data structure is useful in traversing a given graph by breadth first search?a)Queueb)None of the mentionedc)Listd)Stack
Which of the following options are true regarding DFS and BFS traversals in the given graph starting with vertex 1? Both DFS and BFS will always visit the vertices in the same order. DFS order of traversal need not be the same as the BFS order of traversal for the give graph.
The data structure required for Breadth-First Traversal on a graph is?StackArrayQueueTree
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.