MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Graph traversal is different from a tree traversal, because
A
Trees are not connected
B
Graphs may have loops
C
Trees have roots
D
None of these
Explanation: 

Detailed explanation-1: -Tra versal of a graph is different than tree because. Answer: A. There can be a loop in the graph Explanation: You need to maintain an array to keep track of the vertices already visited.

Detailed explanation-2: -A graph is a set of vertices/nodes and edges. A tree is a set of nodes and edges. In the graph, there is no unique node which is known as root. In a tree, there is a unique node which is known as root.

Detailed explanation-3: -The only difference between tree search and graph search is that tree search does not need to store the explored set, because we are guaranteed never to attempt to visit the same state twice. Breadth-first search: Run the generic graph search algorithm with the frontier stored as a (LIFO) queue.

Detailed explanation-4: -Graphs are more complicated as it can have loops and self-loops. In contrast, trees are simple as compared to the graph. The tree is traversed using pre-order, in-order and post-order techniques. On the other hand, for graph traversal, we use BFS (Breadth First Search) and DFS (Depth First Search).

Detailed explanation-5: -The only difference between a graph and a tree is cycle. A graph may contain cycles, a tree cannot. So when you’re going to implement a search algorithm on a tree, you don’t need to consider the existence of cycles, but when working with an arbitrary graph, you’ll need to consider them.

There is 1 question to complete.