Thread: euler tour/traversal anyone please?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    2

    euler tour/traversal anyone please?

    does anyone have an idea how the code looks like when traversing a binary tree in euler's tour??

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    ? I'm confused. Euler tours only exist in connected graphs where each node has an even degree. This isn't the case in most binary trees....

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    2
    i have read that there's a euler's traversal for binary... the preorder, inorder, and postorder traversals are special cases of the Euler tour traversal. however i really don't know how it traverses a binary tree..
    Last edited by devilclaw; 02-02-2008 at 07:27 PM.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    290
    Oh ok, well if you're just looking for the different traversals of a binary tree, they can be easily expressed recursively:
    Code:
    void traverse_in_order(Node * n) {
       if (n->left_child != NULL)
          traverse_in_order(n->left_child);
       
       printf("%d\n", n->value);
    
       if (n->right_child != NULL)
          traverse_in_order(n->right_child);
    }
    You would pass this function a pointer to the root node of your tree. To do preorder and postorder traversals, you just change the order in which you do things.

    For example, for a preorder traversal, you would first print the value, then do left, and then right child.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Project Euler Question
    By Head In Jar Man in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2009, 02:59 PM
  2. Project Euler Solved but want help improving the code Newbie
    By whiterebbit in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2008, 07:00 AM
  3. Euler Cycle
    By nickwokabi in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2005, 09:54 AM