Binary Tree Traversal:How to find Preorder,Inorder And Postorder.

avatar

image.png

Preorder:

The root is visited first, followed by the left subtree in preorder, and finally the right subtree in preorder in this traversal. (RTlTr)

Inorder:

Before going to the root node, you'll go to the left subtree of the root node, then the root node, and finally the right subtree of the root node. (TlRTr)

Postorder:

The root node's left subtree is examined first, then the right subtree, and finally the root node. (TlTrR)

Illustrative Example:

Consider the expression:
(A-B) + (c * (D/E))

binsryss.png

Preorder traversal:
+– A B * C / D E

Inorder traversal:
A – B + C * D / E

Postorder traversal:
A B – C D E / * +

Posted with STEMGeeks



0
0
0.000
0 comments