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:
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.
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