1. ## 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. Originally Posted by ganesh bala
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. Thanks a lot vkaushal21..
I am just Learning Data structures..

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

6. Originally Posted by iMalc
I just joined this forum yesterday ... didn't read homework policy earlier ..

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

7. Originally Posted by ganesh bala
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

8. 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

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

10. 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.