# Prefix Traversal to form Expression from Expression Tree

Expression Tree is used to represent expressions. Let us look at how to form prefix expressions from an expression tree

## Writing Prefix Expression From Expression Tree

Let us how to generate the prefix expression from the tree. A prefix expression is generated from the tree as follows:

1. Consider the root + .
`Prefix expression created so far = + `
2. Next consider the left subtree a * b.
• For a * b, Consider the root of subtree *.
`Prefix expression created so far = + *  `
• For a * b, Consider the left subtree a. Left subtree has only one node a, Hence, first write the same.
`Prefix expression created so far = + * a `
• For a * b, Consider the right subtree b. Right subtree b is just a node.
`Prefix expression created so far = + * a b`
3. Consider the right subtree c . Since the right subtree is just a simple node, there is no more subtrees to be checked
`Prefix expression created so far = + * a b c`

# Prefix Traversal to form Expression from Expression Tree

Expression Tree is used to represent expressions. Let us look at how to form prefix expressions from an expression tree

## Writing Prefix Expression From Expression Tree

Let us how to generate the prefix expression from the tree. A prefix expression is generated from the tree as follows:

1. Consider the root + .
`Prefix expression created so far = + `
2. Next consider the left subtree a * b.
• For a * b, Consider the root of subtree *.
`Prefix expression created so far = + *  `
• For a * b, Consider the left subtree a. Left subtree has only one node a, Hence, first write the same.
`Prefix expression created so far = + * a `
• For a * b, Consider the right subtree b. Right subtree b is just a node.
`Prefix expression created so far = + * a b`
3. Consider the right subtree c . Since the right subtree is just a simple node, there is no more subtrees to be checked
`Prefix expression created so far = + * a b c`