Contents

- 1 There are three methods for graph use traversing.
- 2 How to use IN-ORDER TRAVERSAL?
- 2.1 IN-ORDER TRAVERSAL L D R
- 2.1.0.0.1 Step-1: Start from node L, which means left of each node until the data not found, when we reached node A visit left subtree, then there is no other left subtree node combine with A, so we come with D means data node, we visited with Left(L) Data(D) now where the data is found we write that A and search R there is no Right subtree.
- 2.1.0.0.2 Step-2: Step-1 is completed, after visited node A, there is no other Left or Right subtree, move back to the node, we reached slash(/) where L is visited from Left(L) Data(D) Right(R),
- 2.1.0.0.3 Visit the Data node D, then we found Data node, immediately right that node and go for traverse further nodes until the D not reached at data from LDR. Now, we reached B there no left or right subtree, we go with the arrow shown in step-2, now we right data B and traverse with R, there is no right subtree.
- 2.1.0.0.4 Step-3: B node visited, that’s why? we go back to the node ^ as shown in the above figure, where L is visited but now D is visiting from LDR means to write the data ^ and go with the arrow sign shown in step-3 which is C.write the data C which is the highlight with the circle.
- 2.1.0.0.5 Step-4: After visited node C, take a similar process until all the data nodes have not reached. In the writing manner, we move with help of an arrow sign and write all the data highlighted with a circle. Now we reached E at the end

- 2.1 IN-ORDER TRAVERSAL L D R
- 3 The algorithm used for in-order ?
- 4 How to use PRE-ORDER TRAVERSAL?
- 4.1 2. PRE-ORDER TRAVERSAL D L R
- 4.1.0.0.1 Step-1: In Pre-order traversal, visited all D’s means to write all the data until there is no attached left or right subtree.we visited all the data nodes * / + A.
- 4.1.0.0.2 Step-2: After reached at A go with the Left subtree of + which is already visited, now visit at the right subtree data node that is B, and come back with the arrow sign shown in step -2 figure visited at ^.
- 4.1.0.0.3 Step-3: After visit node ^, we visit in the arrow direction there is a circle on the data node which we visited in that step which is D.

- 4.2 Which Algorithm used for pre-order ?

- 4.1 2. PRE-ORDER TRAVERSAL D L R
- 5 How to use PRE-ORDER TRAVERSAL?
- 5.1 3.POST-ORDER TRAVERSAL L R D
- 5.1.0.0.1 Step-1: In Postorder traversal the data node is, at last, so start with the left subtree and traverse until the last left subtree, once we reached A which is the last node there is no left subtree for traversing means we traverse right and after that Data node.
- 5.1.0.0.2 Therefore, we got the data node now we write A, traverse back with arrow sign shows in fig. step-1 at + and go with right subtree, as you saw in step 1 we reached last node B.
- 5.1.0.0.3 Step-2: As shown in step 2, after reaching the B node we move back to the + it is the data node now we write that data and go with the arrows sign that shown in fig. step-2 we visited at data node C.
- 5.1.0.0.4 Step-3: step-2 completed, visited the C data node we move back with the arrow sign shown in step-3 there is a circle on the node / and D which is the data node in this step.Step-4: We reach D need to move backside, because in post-order traversal the root node traverse at last, so we reached root node * in the final step.

- 5.2 What is the Algorithm used for post-order ?

- 5.1 3.POST-ORDER TRAVERSAL L R D

## There are three methods for graph use traversing.

## How to use IN-ORDER TRAVERSAL?

### IN-ORDER TRAVERSAL L D R

- Traverse the left subtree in Inorder Traversal
- Process(visit) the Data node(root)
- Traverse the Right subtree in Inorder Traversal

*Step-1:** *Start from node L, which means left of each node until the data not found, when we reached node A visit left subtree, then there is no other left subtree node combine with A, so we come with D means data node, we visited with Left(L) Data(D) now where the data is found we write that A and search R there is no Right subtree.

*Step-1:*

**Step-2**: Step-1 is completed, after visited node A, there is no other Left or Right subtree, move back to the node, we reached slash(/) where L is visited from Left(L) Data(D) Right(R),

**Step-2**

###### Visit the Data node D, then we found Data node, immediately right that node and go for traverse further nodes until the D not reached at data from LDR. Now, we reached B there no left or right subtree, we go with the arrow shown in step-2, now we right data B and traverse with R, there is no right subtree.

*Step-3*: B node visited, that’s why? we go back to the node ^ as shown in the above figure, where L is visited but now D is visiting from LDR means to write the data ^ and go with the arrow sign shown in step-3 which is C.write the data C which is the highlight with the circle.

*Step-3*

*Step-4*: After visited node C, take a similar process until all the data nodes have not reached. In the writing manner, we move with help of an arrow sign and write all the data highlighted with a circle. Now we reached E at the end

*Step-4*

## The algorithm used for in-order ?

**FUNCTION**

inorder(struct treenode *root)

{ if(root!=NULL)

inorder(root->left) { printf(“%d”, root->data)

inorder(root->right) } }

## How to use PRE-ORDER TRAVERSAL?

### 2. PRE-ORDER TRAVERSAL **D **L R

- Process(visit) the Data node(root)
- Traverse the left subtree in Preorder Traversal
- Traverse the Right subtree in Preorder Traversal

*Step-1: *In Pre-order traversal, visited all D’s means to write all the data until there is no attached left or right subtree.we visited all the data nodes * / + A.

*Step-1:*

*Step-2: *After reached at A go with the Left subtree of + which is already visited, now visit at the right subtree data node that is B, and come back with the arrow sign shown in step -2 figure visited at ^.

*Step-2:*

*Step-3**: *After visit node ^, we visit in the arrow direction there is a circle on the data node which we visited in that step which is D.

*Step-3*

*:*

### Which Algorithm used for pre-order ?

**FUNCTION**

preorder(struct treenode *root)

{ if(root!=NULL)

{ printf(“%d”,root->data)

preorder(root->left)

preorder(root->right) } }

## How to use PRE-ORDER TRAVERSAL?

### 3.POST-ORDER TRAVERSAL L R D

- Traverse the left subtree in Postorder Traversal
- Traverse the Right subtree in Postorder Traversal
- Process(visit) the Data node(root)

*Step-1: *In Postorder traversal the data node is, at last, so start with the left subtree and traverse until the last left subtree, once we reached A which is the last node there is no left subtree for traversing means we traverse right and after that Data node.

*Step-1:*

###### Therefore, we got the data node now we write A, traverse back with arrow sign shows in fig. step-1 at + and go with right subtree, as you saw in step 1 we reached last node B.

*Step-2*: As shown in step 2, after reaching the B node we move back to the + it is the data node now we write that data and go with the arrows sign that shown in fig. step-2 we visited at data node C.

*Step-2*

*Step-3*: step-2 completed, visited the C data node we move back with the arrow sign shown in step-3 there is a circle on the node / and D which is the data node in this step.

*Step-4*: We reach D need to move backside, because in post-order traversal the root node traverse at last, so we reached root node * in the final step.

*Step-3*

*Step-4*