• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Dan D'amico
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup 5 4 10 8 6 19 11 is correct
 
Dan D'amico
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes. my mistake.
first child and then the father
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what answer did you get?
 
Dan D'amico
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:So, what answer did you get?

i will get on it in one hour . still try to solve some problem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!