Results 1 to 3 of 3
  1. #1
    Heanre is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default 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. #2
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    265
    Rep Power
    2

    Default 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. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,804
    Rep Power
    5

    Default 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.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. insertion order for complete binary search tree
    By scottmulla in forum New To Java
    Replies: 3
    Last Post: 10-20-2011, 01:47 PM
  2. how do i do inorder traversal os a 2-3-4 tree?
    By Meta in forum New To Java
    Replies: 0
    Last Post: 04-12-2011, 05:43 AM
  3. Replies: 3
    Last Post: 12-06-2010, 05:42 PM
  4. need help with post order traversal
    By Metastar in forum New To Java
    Replies: 3
    Last Post: 11-08-2010, 09:40 PM
  5. Level order binary tree traversal
    By H3rtaherta in forum New To Java
    Replies: 1
    Last Post: 04-20-2009, 08:34 AM

Posting Permissions

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