Question & Answer: Write the order in which the nodes of the following tree are visited using depth-first search. Then write the order in w…..

5. Trees (10 points) Write the order in which the nodes of the following tree are visited using depth-first search. Then write the order in which they are visited using breadth-first search. G) (H Depth-first search: A BFCOGHBE Breadth-first search

Write the order in which the nodes of the following tree are visited using depth-first search. Then write the order in which they are visited using breadth-first search. Depth-first search: Breadth-first search:

Expert Answer

 

preorder traversal of a tree is the Depth-first search of tree as it tries to go deeper into the tree before checking the siblings.
PREORDER-TRAVERSE(tree)

if (tree not empty)
  visit root of tree
  PREORDER-TRAVERSE(left subtree)
  PREORDER-TRAVERSE(right subtree)

hence the DDS will be: A B F C D G H E



Breath-first search: 
Traversing the tree level by level i.e exploring the breadth of tree first and then going to deeper levels is BFS:
BFS traversal will be:  A B C D E F G H
Still stressed from student homework?
Get quality assistance from academic writers!