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
Don't use plagiarized sources. Get Your Custom Essay on
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…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
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