Condition X: node -> left is not equal null
Function preordertraverse(node) { print node-value if (condition ) {preordertraverse(node-left)} if (condition y) {preordertraverse(node-right)} return }
- You move from the left subtree to the root, then to the right subtree when using Inorder. You move from the root to the left subtree for Preorder before moving to the right subtree. You move from the left subtree to the right subtree and then to the root in Post order.
- Another DFS variation is called Preorder Traversal. A recursive function's atomic actions are identical to inorder traversal but are performed in a different order. Here, we start by looking at the current node before moving on to the left sub-tree.
- Recursively process the left subtree, the root, and then the right subtree to process all nodes in a tree. often referred to as symmetric traversal.
- A pointer to the tree's root node is supplied with the first call to the traversal function. The traversal function makes the desired number of trips to rt and any offspring it may have. A preorder traversal, for instance, directs that rt be visited before its offspring. The following can be used to quickly implement this.
#SPJ2