Definition: Process all nodes of a tree by processing the root, then recursively processing all subtrees. Also known as prefix traversal.
What is a preorder traversal?
Tree traversal means visiting all the nodes of a tree exactly once. Visiting can be interpreted as doing something to the node, for example, printing the value contained in it. Pre-order traversal is one of the many ways to traverse a tree. It is mainly used when a tree needs to be duplicated.
What is preorder traversal example?
Preorder Traversal. For example, we might wish to make sure that we visit any given node before we visit its children. ... The first node printed is the root. Then all nodes of the left subtree are printed (in preorder) before any node of the right subtree.