# Thread: binary tree post order , inorder and pre order traversal

1. Member
Join Date
Jan 2014
Posts
2
Rep Power
0

## binary tree post order , inorder and pre order traversal

our teacher already taught us this lesson a semester ago but my teacher now explained it differently, i went to youtube and they also got a different explanation..

anyone who can either teach or post a link to the accurate explanation of binary trees in java?

thanks

2. Senior Member
Join Date
Apr 2013
Location
Sweden
Posts
272
Rep Power
4

## Re: binary tree post order , inorder and pre order traversal

what exactly do you want to know? about the traversals?

the algorithm is simple

inorder: traverse the left subtree, visit node, traverse the right subtree
preorder: visit node, traverse the left subtree, traverse the right subtree
postorder: traverse the left subtree, traverse the right subtree, visit node

the traversals are implemented recursively and are very simple to implement in fact.

3. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,659
Rep Power
9

## Re: binary tree post order , inorder and pre order traversal

The three traversals you mention has to do with when you visit the root (i.e. take some action) in relationship to traversing the child nodes. Keep in mind that the child nodes may also be roots in their own right, so the traversal can be recursive.

Pre-order: root, left, right.
In-order: left, root, right.
Post-order: left, right, root.

Here is a link for an explanation. Tree traversal - Wikipedia, the free encyclopedia.
Note: if you populate a tree of numbers (or any other sortable item) such that the left node is less than the root and the right node is greater than the root, an in-order traversal will result in the items being displayed in ascending-sorted order.

Regards,
Jim
Last edited by jim829; 01-26-2014 at 04:43 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•