Tree Traversal..

This is a discussion on Tree Traversal.. within the C Programming forums, part of the General Programming Boards category; Hi, for this, 0123456789 i constructed Binary search tree... now,i want to know preorder,postorder for this..... 5 / \ 3 ...

  1. #1
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    Tree Traversal..

    Hi,

    for this, 0123456789 i constructed Binary search tree... now,i want to know

    preorder,postorder for this.....

    5
    / \
    3 8
    / \ / \
    1 4 7 9
    / \ /
    0 2 6

    Is this correct?? how to traverse?? i googled it.. But i was confused thats why i am posting here...

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    12
    Quote Originally Posted by ganesh bala View Post
    Hi,

    for this, 0123456789 i constructed Binary search tree... now,i want to know

    preorder,postorder for this.....

    5
    / \
    3 8
    / \ / \
    1 4 7 9
    / \ /
    0 2 6

    Is this correct?? how to traverse?? i googled it.. But i was confused thats why i am posting here...
    No idea about what you are aiming at from 0123456789, anyways I can give you the pre and posorder traversal of the tree you have drawn

    POST order : - 0214367985
    PRE order : - 5310248769

    How to traverse: -

    POST order ... First left child then right child the root
    now as you see left = 3 , right = 8, root 5
    but again 3 is not leaf so 3 is in itself root.. so we need to satisfy the condition here too..

    thus left = 1 right = 4 root 3
    oops ... 1 is root ...
    left = 0 right = 2 root = 1
    0 is leaf -- write it -> 0
    2 is leaf --- write it -> 02
    1 is root but children already dealed ---> 021 ... .... ..

    preorder should be clear

  3. #3
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    Wink

    Thanks a lot vkaushal21..
    I am just Learning Data structures..

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Please don't just give out answers. See the homework policy.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    Talking

    Its not Home Work .. Just i want to know it ...

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    12
    Quote Originally Posted by iMalc View Post
    Please don't just give out answers. See the homework policy.
    I just joined this forum yesterday ... didn't read homework policy earlier ..

    thanks for the info.. i will mind that in future

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by ganesh bala View Post
    Its not Home Work .. Just i want to know it ...
    You are trying to learn, however, and being given the answer is how you learn how to copy others. Learning how it works yourself by working it out, you learn how to solve the problem. Along the lines of:
    Give a man a fish, and you have to feed him every day.
    Teach a man to fish, and you never need to give him food.

    In this case, it's answers in the forum and problem solving instead of fish and fishing, but the same idea applies.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    I always heard it as

    Give a man a fish and feed him for a day.
    Teach a man to fish and feed him for a lifetime!

    I think it sounds more poetic that way

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Bladactania View Post
    I always heard it as

    Give a man a fish and feed him for a day.
    Teach a man to fish and feed him for a lifetime!

    I think it sounds more poetic that way
    Yeah, I guess that's better - I was writing it from memory...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    It is one of my favorite sayings... My other favorite is

    God grant me the serenity to accept the things I cannot change, the courage to change the things I can and the wisdom to know the difference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Tree traversal
    By recluse in forum C Programming
    Replies: 4
    Last Post: 12-05-2004, 03:00 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21