programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# i tried to draw this recursion on a paper. to understand it better.

Dan D'amico
Ranch Hand
Posts: 94
every time i have a question like this. i draw to myself the steps.
as it should be on the stack.
here i find it a little more difficult.

Please dont tell the answer. just if someone can tell me. or even draw and upload here. what excactly happen on the stack and then i will figure out the correct answer.

Knute Snortum
Sheriff
Posts: 4276
127
• 1
Getting you the "stack" is most of the answer. Instead I'll see if I can start you off:

Let's see if we come up with the same answer and why.

Liutauras Vilda
Sheriff
Posts: 4917
334
Over here two things are important to understand solving this problem.

1. Recursion
2. Postorder tree traversal:
Traverse the left subtree
Traverse the right subtree
Visit the root

Dan D'amico
Ranch Hand
Posts: 94
Liutauras Vilda wrote:Over here two things are important to understand solving this problem.

1. Recursion
2. Postorder tree traversal:
Traverse the left subtree
Traverse the right subtree
Visit the root

yes. i understand recursion. not sharp as i want but i do. need to practice on it.
post traversal on this tree is 4 5 8 10 6 19 11 if i'm correct

Liutauras Vilda
Sheriff
Posts: 4917
334
Dan D'amico wrote:post traversal on this tree is 4 5 8 10 6 19 11 if i'm correct

Nope. I think 5, 4, 10, 8, 6, 19, 11. Remember, you traverse recursively.

Zulfiquiar Khan
Greenhorn
Posts: 7
yup 5 4 10 8 6 19 11 is correct

Dan D'amico
Ranch Hand
Posts: 94
yes. my mistake.
first child and then the father

Liutauras Vilda
Sheriff
Posts: 4917
334
So, what answer did you get?

Dan D'amico
Ranch Hand
Posts: 94
Liutauras Vilda wrote:So, what answer did you get?

i will get on it in one hour . still try to solve some problem