recursive algorithm

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 7
Reputation: bajanstar is an unknown quantity at this point 
Solved Threads: 0
bajanstar bajanstar is offline Offline
Newbie Poster

recursive algorithm

 
1
  #1
Sep 27th, 2006
hi, can someone help me with writing down a recursive algorithm for traversing a binary tree in reverse-postorder that also returns the rank of each node? So far i have (and i know thatit isnt much but this problem giving me issues).

  1.  
  2. postorder:
  3. save current posistion
  4. if(lchild)
  5. move to lchild
  6. postorder
  7. if(sibling)
  8. move to sibling
  9. postorder
  10. endif
  11. endif
  12. restore saved position
  13. visit//do something with the node

i hope that someone can give me some serious help thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: recursive algorithm

 
1
  #2
Sep 27th, 2006
What language is this, Basic? This is the C/C++ forum, please ask your question in the forum for the appropiate lanuage.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 7
Reputation: bajanstar is an unknown quantity at this point 
Solved Threads: 0
bajanstar bajanstar is offline Offline
Newbie Poster

Re: recursive algorithm

 
1
  #3
Sep 27th, 2006
no its just an algorithm for the problem. Im suppose to be writing it in C or C++ but i decided to write the algorithm first. But im having problems with it.So any one who can help me solve this problem i would greatly appreciate it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,623
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: recursive algorithm

 
0
  #4
Sep 28th, 2006
What do you exactly mean by reverse postorder? In postorder the value is accessed after accessign all the left and the right children or branches.
So if you want reverse then it must mean preorder traversal.

[quote]
Preorder:

1. Print out the value and save the node or value to stack.
2. If left child not null call Preorder (left)
3. If right child not null call Preorder (right).

If this is not your problem stmt then restate it with examples.
Best of luck,
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: recursive algorithm

 
1
  #5
Sep 28th, 2006
Originally Posted by ~s.o.s~ View Post
So if you want reverse then it must mean preorder traversal.
It seems odd that he would state preorder as being reverse post order. Why not just as for a preorder traversal algo. But than nothing surprises me these days so you could be right?
Last edited by iamthwee; Sep 28th, 2006 at 2:45 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,623
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: recursive algorithm

 
1
  #6
Sep 28th, 2006
Originally Posted by iamthwee View Post
It seems odd that he would state preorder as being reverse post order. Why not just as for a preorder traversal algo. But than nothing surprises me these days so you could be right?
Yes its possible I may be wrong but lookign from his code and the limited senario he has painted in front of me, i thought maybe he didnt know about preorder and needed some direction. But then again you cant know the mind of these young developers, maybe he wouldb be the first one to write a technical paper on Reverse Postorder :mrgreen:
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: recursive algorithm

 
3
  #7
Sep 29th, 2006
Reverse postorder means you traverse each node's children from right to left.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC