traversing a tree means visiting each node in a specified order. there are different ways to...
DESCRIPTION
A binary tree (not a binary search tree) can also be used to represent an algebraic expression that involves the binary arithmetic operators +, -, /, and *. The root node holds an operator, and each of its subtrees represents either a variable name (like A, B, or C) or another expression. The following slides depicts the Tree traversals using Preorder Traversal Inorder Traversal Postorder TraversalTRANSCRIPT
![Page 1: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/1.jpg)
BINARY TREE TRAVERSAL
![Page 2: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/2.jpg)
TRAVERSING A BINARY TREE• Traversing a tree means visiting each node in a specified
order. • There are different ways to traverse a tree.
![Page 3: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/3.jpg)
BINARY TREE• A binary tree (not a binary search tree) can also be used to
represent an algebraic expression that involves the binary arithmetic operators +, -, /, and *.
• The root node holds an operator, and each of its subtrees represents either a variable name (like A, B, or C) or another expression.
• The following slides depicts the Tree traversals using
Preorder Traversal
Inorder Traversal
Postorder Traversal
![Page 4: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/4.jpg)
PRE-ORDER BINARY TREE• In Pre-order Traversal the order of traversing the nodes is as
follows. Root Left sub-tree Right sub-tree
Note :
• Dotted lines and Dotted Circles in the BST diagram represent NULL Nodes.
![Page 5: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/5.jpg)
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
+
* /
A B C D
POST-ORDER
• Consider this tree for traversal and follow the algorithm on the right side for traversal.
![Page 6: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/6.jpg)
+
* /
A B C D
PRE-ORDER
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
preOrder( + )
• Start the execution of preOrder function with localRoot as “ + “.•Pushes the method call into stack.
![Page 7: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/7.jpg)
+
* /
A B C D
PRE-ORDER
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
• Check if localRoot value is null or not.
preOrder( + )
![Page 8: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/8.jpg)
+
* /
A B C D
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
PRE-ORDER
• Printing the localRoot value using diplayNode() method.
preOrder( + )
![Page 9: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/9.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ * “ as the localRoot.• Pushes the method call into stack.
+ preOrder( + )preOrder( *)
![Page 10: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/10.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ * “.
+ preOrder( + )preOrder( *)
![Page 11: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/11.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
+ preOrder( + )preOrder( *)
![Page 12: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/12.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
+ * preOrder( + )preOrder( *)
![Page 13: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/13.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ A “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( A )preOrder( * )
+ *
![Page 14: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/14.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ A “.
preOrder( + )
preOrder( A )preOrder( * )
+ *
![Page 15: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/15.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( A )preOrder( * )
+ *
![Page 16: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/16.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
preOrder( + )
preOrder( A )preOrder( * )
+ * A
![Page 17: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/17.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ (NULL) as the localRoot.•Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 18: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/18.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “ (NULL).
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 19: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/19.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 20: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/20.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As the results evaluates to true call returns to previous stage in the stack.• Then it executes remaining statements in that method call as indicated here by arrow.
preOrder( + )
preOrder( A )preOrder( * )
+ * A
![Page 21: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/21.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ (NULL) as the localRoot. • Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 22: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/22.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “ (NULL).
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 23: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/23.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.• As the results evaluates to true, call returns to previous stage in the stack.
preOrder( + )
preOrder( )preOrder( A )preOrder( * )
+ * A
![Page 24: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/24.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements at this stage also completed, call returns to the previous stage in the stack.
preOrder( + )
preOrder( A )preOrder( * )
+ * A
![Page 25: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/25.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•Then executes remaining statements in that stage as indicated here by arrow.
preOrder( + )preOrder( * )
+ * A
![Page 26: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/26.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ B “ as the localRoot. • Pushes the method call into stack.
preOrder( + )
preOrder( B )preOrder( * )
+ * A
![Page 27: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/27.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ B “.
preOrder( + )
preOrder( B )preOrder( * )
+ * A
![Page 28: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/28.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( B )preOrder( * )
+ * A
![Page 29: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/29.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
preOrder( + )
preOrder( B )preOrder( * )
+ * A B
![Page 30: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/30.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ (NULL) as the localRoot.•Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( B )preOrder( * )
+ * A B
![Page 31: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/31.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “ (NULL).
preOrder( + )
preOrder( )preOrder( B )preOrder( * )
+ * A B
![Page 32: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/32.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.• As the results evaluates to true call returns to previous stage in the stack.
preOrder( + )
preOrder( B )preOrder( * )
+ * A B
![Page 33: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/33.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•Then executes remaining statements in that method call as indicated here by arrow.
preOrder( + )
preOrder( B )preOrder( * )
+ * A B
![Page 34: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/34.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ (NULL) as the localRoot. • Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( B )preOrder( * )
+ * A B
![Page 35: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/35.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “ (NULL).
preOrder( + )
preOrder( )preOrder( B )preOrder( * )
+ * A B
![Page 36: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/36.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( B )preOrder( * )
+ * A B
![Page 37: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/37.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•As the results evaluates to true, call returns to previous stage in the stack.
preOrder( + )
preOrder( B )preOrder( * )
+ * A B
![Page 38: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/38.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements in the previous stage also completed, call returns to the previous stage in the stack.
preOrder( + )preOrder( * )
+ * A B
![Page 39: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/39.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements in the previous stage also completed, call returns to the previous stage in the stack.
preOrder( + )+ * A B
![Page 40: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/40.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•Then executes remaining statements in that stage as indicated here by arrow.
preOrder( + )
![Page 41: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/41.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ / “ as the localRoot.• Pushes the method call into stack.
preOrder( + )preOrder( / )
+ * A B
![Page 42: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/42.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ / “.
preOrder( + )preOrder( / )
+ * A B
![Page 43: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/43.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )preOrder( / )
+ * A B
![Page 44: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/44.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
preOrder( + )preOrder( / )
+
* /
A B C D
+ * A B /
![Page 45: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/45.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ C “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B /
![Page 46: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/46.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ C “.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B /
![Page 47: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/47.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B /
![Page 48: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/48.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B / C
![Page 49: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/49.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ * “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 50: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/50.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 51: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/51.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 52: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/52.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER • As the results evaluates to true call returns to previous stage in the stack.• Then executes remaining statements in that method call as indicated here by arrow.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B / C
![Page 53: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/53.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ * “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 54: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/54.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•Start the execution of preOrder function with localRoot as “ “.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 55: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/55.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( C )preOrder( / )
+ * A B / C
![Page 56: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/56.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.•As the results evaluates to true call returns to previous stage in the stack.
preOrder( + )
preOrder( C )preOrder( / )
+ * A B / C
![Page 57: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/57.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
preOrder( + )preOrder( / )
+ * A B / C
![Page 58: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/58.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ * “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C
![Page 59: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/59.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
•Start the execution of preOrder function with localRoot as “ D “.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C
![Page 60: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/60.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C
![Page 61: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/61.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Printing the localRoot value using diplayNode () method.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C D
![Page 62: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/62.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 63: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/63.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 64: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/64.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 65: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/65.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As the results evaluates to true call returns to previous stage in the stack.•Then executes remaining statements in that method call as indicated here by arrow.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C D
![Page 66: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/66.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Calling the preOrder function with “ “ as the localRoot.• Pushes the method call into stack.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 67: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/67.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Start the execution of preOrder function with localRoot as “ “.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 68: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/68.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.
preOrder( + )
preOrder( )preOrder( D )preOrder( / )
+ * A B / C D
![Page 69: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/69.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• Check if localRoot value is null or not.• As the results evaluates to true call returns to previous stage in the stack.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C D
![Page 70: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/70.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
preOrder( + )
preOrder( D )preOrder( / )
+ * A B / C D
![Page 71: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/71.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
preOrder( + )preOrder( / )
+ * A B / C D
![Page 72: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/72.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
preOrder( + )+ * A B / C D
![Page 73: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/73.jpg)
private void preOrder(node localRoot){
if(localRoot != null) {
localRoot.displayNode();
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}}
+
* /
A B C D
PRE-ORDER
• As the stack is empty the call comes out of the algorithm.
+ * A B / C D
![Page 74: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/74.jpg)
In Order Binary Tree
• In In-order Traversal the order of traversing the nodes is as follows.
Left sub-tree Root Right sub-tree
• An In-order traversal is most commonly used in binary search tree because it visits all the nodes in ascending order, based on their key values.
• If you want to create a sorted list of the data in a binary tree, this is one way to do it.
![Page 75: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/75.jpg)
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
+
* /
A B C D
POST-ORDER
• Consider this tree for traversal and follow the algorithm on the right side for traversal.
![Page 76: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/76.jpg)
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} } +
* /
A B C D
IN-ORDER
• Start the execution of inOrder function with localRoot as “ + “.• Pushes the method call into stack.
inOrder( + )
![Page 77: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/77.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
![Page 78: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/78.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ * “ as the localRoot.• Pushes the method call into stack.
inOrder( + )inOrder( * )
![Page 79: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/79.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of preOrder function with localRoot as “ * “.
inOrder( + )inOrder( * )
![Page 80: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/80.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )inOrder( * )
![Page 81: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/81.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ A “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder (A )inOrder( * )
![Page 82: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/82.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ A “.
inOrder( + )
inOrder( A )inOrder( * )
![Page 83: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/83.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( A )inOrder( * )
![Page 84: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/84.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
![Page 85: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/85.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
![Page 86: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/86.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
![Page 87: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/87.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER • As the results evaluates to true call returns to previous stage in the stack.• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )
inOrder( A )inOrder( * )
![Page 88: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/88.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )
inOrder( A )inOrder( * )
A
![Page 89: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/89.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
A
![Page 90: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/90.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
A
![Page 91: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/91.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( A )inOrder( * )
A
![Page 92: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/92.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( A )inOrder( * )
A
![Page 93: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/93.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )inOrder( * )
A
![Page 94: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/94.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )inOrder( * )
A *
![Page 95: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/95.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ B “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( B )inOrder( * )
A *
![Page 96: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/96.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ B “.
inOrder( + )
inOrder( B )inOrder( * )
A *
![Page 97: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/97.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( B )inOrder( * )
A *
![Page 98: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/98.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A *
![Page 99: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/99.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A *
![Page 100: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/100.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A *
![Page 101: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/101.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( B )inOrder( * )
A *
![Page 102: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/102.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )
inOrder( B )inOrder( * )
A *
![Page 103: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/103.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )
inOrder( B )inOrder( * )
A * B
![Page 104: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/104.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A * B
![Page 105: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/105.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A * B
![Page 106: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/106.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( B )inOrder( * )
A * B
![Page 107: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/107.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
•As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( B )inOrder( * )
A * B
![Page 108: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/108.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
inOrder( + )inOrder( * )
A * B
![Page 109: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/109.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + ) A * B
![Page 110: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/110.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + ) A * B +
![Page 111: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/111.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ / “ as the localRoot.• Pushes the method call into stack.
inOrder( + )inOrder( / )
A * B +
![Page 112: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/112.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ / “.
inOrder( + )inOrder( / )
A * B +
![Page 113: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/113.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )inOrder( / )
A * B +
![Page 114: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/114.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ C “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( C )inOrder( / )
A * B +
![Page 115: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/115.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ C “.
inOrder( + )
inOrder( C )inOrder( / )
A * B +
![Page 116: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/116.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( C )inOrder( / )
A * B +
![Page 117: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/117.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
Calling the inOrder function with “ “ as the localRoot.Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B +
![Page 118: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/118.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B +
![Page 119: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/119.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B +
![Page 120: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/120.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( C )inOrder( / )
A * B +
![Page 121: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/121.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )
inOrder( C )inOrder( / )
A * B +
![Page 122: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/122.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )
inOrder( C )inOrder( / )
A * B + C
![Page 123: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/123.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B + C
![Page 124: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/124.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
•Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B + C
![Page 125: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/125.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( C )inOrder( / )
A * B + C
![Page 126: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/126.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( C )inOrder( / )
A * B + C
![Page 127: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/127.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )inOrder( / )
A * B + C
![Page 128: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/128.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )inOrder( / )
A * B + C /
![Page 129: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/129.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ D “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C /
![Page 130: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/130.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ D “.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C /
![Page 131: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/131.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C /
![Page 132: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/132.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C /
![Page 133: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/133.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C /
![Page 134: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/134.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C /
![Page 135: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/135.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C /
![Page 136: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/136.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C /
![Page 137: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/137.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Printing the localRoot value using diplayNode () method.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C / D
![Page 138: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/138.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Calling the inOrder function with “ “ as the localRoot.• Pushes the method call into stack.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C / D
![Page 139: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/139.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Start the execution of inOrder function with localRoot as “ “.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C / D
![Page 140: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/140.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• Check if localRoot value is null or not.
inOrder( + )
inOrder( )inOrder( D )inOrder( / )
A * B + C / D
![Page 141: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/141.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
inOrder( + )
inOrder( D )inOrder( / )
A * B + C / D
![Page 142: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/142.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
•As all the statements in this stage also completed, call returns to the previous stage in the stack.
inOrder( + )inOrder( / )
A * B + C / D
![Page 143: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/143.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
•As all the statements in this stage also completed, call returns to the previous stage in the stack.
inOrder( + ) A * B + C / D
![Page 144: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/144.jpg)
+
* /
A B C D
private void inOrder(node localRoot){
if(localRoot != null){
inOrder(localRoot.leftChild);
localRoot.displayNode();
inOrder(localRoot.rightChild);
} }
IN-ORDER
• As the stack is empty the call comes out of the algorithm.
A * B + C / D
![Page 145: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/145.jpg)
Post Order Binary Tree
• In Post-order Traversal the order of traversing the nodes is as follows.
Left sub-tree Right sub-tree Root
![Page 146: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/146.jpg)
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
+
* /
A B C D
POST-ORDER
• Consider this tree for traversal and follow the algorithm on the right side for traversal.
![Page 147: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/147.jpg)
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
+
* /
A B C D
POST-ORDER
postOrder( + )
• Start the execution of inOrder function with localRoot as “ + “.• Pushes the method call into stack.
![Page 148: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/148.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
![Page 149: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/149.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ * “as the localRoot.• Pushes the method call into stack.
postOrder( + )postOrder( * )
![Page 150: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/150.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ * “.
postOrder( + )postOrder( * )
![Page 151: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/151.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )postOrder( * )
![Page 152: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/152.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ A “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( A )postOrder( * )
![Page 153: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/153.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ A “.
postOrder( + )
postOrder( A )postOrder( * )
![Page 154: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/154.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( A )postOrder( * )
![Page 155: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/155.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ * “as the localRoot. • Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 156: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/156.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 157: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/157.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 158: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/158.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( A )postOrder( * )
![Page 159: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/159.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( A )postOrder( * )
![Page 160: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/160.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 161: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/161.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 162: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/162.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( A )postOrder( * )
![Page 163: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/163.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( A )postOrder( * )
![Page 164: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/164.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( A )postOrder( * )
![Page 165: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/165.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )
postOrder( A )postOrder( * )
A
![Page 166: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/166.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + )postOrder( * )
A
![Page 167: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/167.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )postOrder( * )
A
![Page 168: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/168.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ B“ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 169: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/169.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ B “.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 170: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/170.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 171: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/171.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 172: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/172.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 173: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/173.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 174: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/174.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 175: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/175.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 176: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/176.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 177: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/177.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 178: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/178.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( B )postOrder( * )
A
![Page 179: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/179.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 180: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/180.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( B )postOrder( * )
A
![Page 181: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/181.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )
postOrder( B )postOrder( * )
A B
![Page 182: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/182.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
•As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + )postOrder( * )
A B
![Page 183: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/183.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )postOrder( * )
A B
![Page 184: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/184.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )postOrder( * )
A B *
![Page 185: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/185.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + ) A B *
![Page 186: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/186.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + ) A B *
![Page 187: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/187.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ / “ as the localRoot.• Pushes the method call into stack.
postOrder( + )postOrder( / )
A B *
![Page 188: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/188.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ / “.
postOrder( + )postOrder( / )
A B *
![Page 189: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/189.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )postOrder( / )
A B *
![Page 190: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/190.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ C“ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 191: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/191.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ C “.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 192: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/192.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 193: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/193.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 194: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/194.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 195: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/195.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 196: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/196.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 197: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/197.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
•Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 198: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/198.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 199: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/199.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 200: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/200.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( C )postOrder( / )
A B *
![Page 201: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/201.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 202: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/202.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( C )postOrder( / )
A B *
![Page 203: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/203.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )
postOrder( C )postOrder( / )
A B * C
![Page 204: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/204.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + )postOrder( / )
A B * C
![Page 205: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/205.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )postOrder( / )
A B * C
![Page 206: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/206.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ D“ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 207: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/207.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ D “.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 208: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/208.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 209: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/209.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 210: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/210.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 211: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/211.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 212: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/212.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 213: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/213.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 214: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/214.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Calling the postOrder function with “ “ as the localRoot.• Pushes the method call into stack.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 215: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/215.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Start the execution of postOrder function with localRoot as “ “.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 216: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/216.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Check if localRoot value is null or not.
postOrder( + )
postOrder( )postOrder( D )postOrder( / )
A B * C
![Page 217: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/217.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As the results evaluates to true call returns to previous stage in the stack.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 218: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/218.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )
postOrder( D )postOrder( / )
A B * C
![Page 219: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/219.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )
postOrder( D )postOrder( / )
A B * C D
![Page 220: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/220.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + )postOrder( / )
A B * C D
![Page 221: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/221.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + )postOrder( / )
A B * C D
![Page 222: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/222.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + )postOrder( / )
A B * C D /
![Page 223: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/223.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
•As all the statements in this stage also completed, call returns to the previous stage in the stack.
postOrder( + ) A B * C D /
![Page 224: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/224.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Then executes remaining statements in that method call as indicated here by arrow.
postOrder( + ) A B * C D /
![Page 225: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/225.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• Printing the localRoot value using diplayNode () method.
postOrder( + ) A B * C D / +
![Page 226: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/226.jpg)
+
* /
A B C D
private void postOrder(node localRoot){
if(localRoot != null){
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
localRoot.displayNode();
} }
POST-ORDER
• As all the statements in this stage also completed, call returns to the previous stage in the stack.
A B * C D / +
![Page 227: Traversing a tree means visiting each node in a specified order. There are different ways to traverse a tree. Tree Traversing Depth first search Pre-orderIn-orderPost-order](https://reader035.vdocuments.net/reader035/viewer/2022062401/5a4d1aec7f8b9ab05997b2ba/html5/thumbnails/227.jpg)
THANK YOU