 Welcome to this course on data structures and algorithms. Last time we saw what a binary tree is. Today, we shall look at the traversal of the binary trees. Traversing binary trees we had noted last time that can be done in three different fashions. One is called the pre-order traversal. The simple mechanism of pre-order traversal is we display the root, then we traverse left recursively. So, then we will display 40, 40, 20, 25, 23, all of them will be covered first. And then finally, we traverse right recursively. Whatever the order that we get is actually equivalent to a pre-order traverse. What is an in-order traversal? In-order traversal, we first traverse the left recursively, then we display the root and then we traverse the right recursively. So, a very simple change of the order creates an in-order traversal. You would have guessed by now what would be the post-order traversal. Here, we traverse the left recursively, then right recursively and then we display the root. So, this will be the order in which for example, the data will be printed out if we do a post-order traversal. First, 23 will come, then 25, then 20, then 40, then 85, then 80, then 95, then 90 and finally, 60. What exactly is the use of this left, the post-order pre-order and in-order traversal? Well, as I had hinted in last time, we had seen the way in which expressions are written. Originally, we write them in in-fix notation, but we had noticed that if we represent them as prefix or post-fix, then we will be able to evaluate them very easily because the priority of the operators is implicitly taken care of in the prefix and post-fix notation. We shall see an example of these notations here as applications of the traversals. Consider the simple expression a plus b that we write. We recall that in prefix, we would have written it as plus a b and in post-fix, we would have written it as a b plus. If we create a binary tree with plus as the root and parent and a on the left, b on the right, you will notice that if we traverse it in in-order, pre-order and post-order, we will get exactly this sequence of symbols appearing as output. Here is another example, a plus b multiplied by a minus b is a way in which we normally see this as an in-fix operator. The prefix expression would be written as star plus a b minus a b and post-fix will be written as a b plus a b minus star. Notice that if the tree is constructed like this, then in-order traversal, pre-order traversal and post-order traversal will give us exactly these three types of expressions printed out. Here is another example, a slightly more complex expression. In fixed notation, we would have written this as a raise to b multiplied by c plus d into e minus f all divided by g. The tree for representing this expression is shown here. The prefix representation of this expression will be like this and post-fix expression, representation of the same expression will be like this. You will see by doing the in-order traversal, pre-order traversal and post-fix post-order traversal, you will get exactly this sequence of symbols coming out from the traversal of this tree. It is interesting to note that in all the trees which we have used to represent expressions, all operands like a, b, c, d, e, f, g appear as leaf nodes. All operators appear as parent nodes of these leaf nodes and if you look carefully, the order in which these operators appear in the tree implicitly represent the priority in which these operations are to be carried out. This is exactly the reason why a prefix and the post-fix representation of the expression is so easily derived by pre-order traversal and post-order traversal of these trees. We are seen in this session some examples and utilization of pre-order, post-order and in order traversal in the context of writing expressions representing them as trees, so that we can easily get the prefix, post-fix and in-fix notation of the same expression by using any one of the tree traversals. Thank you.