943,699 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1992
  • C++ RSS
Mar 24th, 2009
0

Help explain successor binary search tree code

Expand Post »
Binary Search tree help
Can somebody explain to me what this code is doing step by step?, thanks
Java Syntax (Toggle Plain Text)
  1.  
  2. TREE-SUCCESSOR(x)
  3. 1 if right[x] ≠ NIL
  4. 2 then return TREE-MINIMUM (right[x])
  5. 3 y ← p[x]
  6. 4 while y ≠ NIL and x = right[y]
  7. 5 do x ← y
  8. 6 y ← p[y]
  9. 7 return y
Reputation Points: 10
Solved Threads: 0
Light Poster
Dio1080 is offline Offline
47 posts
since Aug 2007
Mar 24th, 2009
0

Re: Help explain successor binary search tree code

have no idea because it isn't c or c++.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Mar 24th, 2009
0

Re: Help explain successor binary search tree code

Looks like lua
Reputation Points: 38
Solved Threads: 13
Junior Poster
SeeTheLite is offline Offline
109 posts
since Mar 2009
Apr 11th, 2010
-3
Re: Help explain successor binary search tree code
Hi , the comments describe the code in a better way.
our job is to find the successor.

Click to Expand / Collapse  Quote originally posted by Dio1080 ...
Binary Search tree help
Can somebody explain to me what this code is doing step by step?, thanks
Java Syntax (Toggle Plain Text)
  1.  
  2. TREE-SUCCESSOR(x)
  3. 1 if right[x] ≠ NIL
  4. 2 then return TREE-MINIMUM (right[x]) // if the node x has a right child , simply return that , that is the successor.
  5. //now is the tricky part .. there is no node as the right child,
  6. traverse back along the parent path , which ever node along the path has a right childe is the successor
  7. 3 y ← p[x] // y <- parent of x
  8. 4 while y ≠ NIL and x = right[y] // as long as y is not nil and the current node is the right child , we keep going to the top, if it is the left child , we simply return the parent y.
  9. 5 do x ← y // make the parent as the current node.
  10. 6 y ← p[y] // fetch the parent of the current node just set.
  11. 7 return y // this will return either NIL , if we shoot past the root of the tree or we are not the right child of the parent , left child implies this node will be the successor.

Hope this helps!
Reputation Points: 5
Solved Threads: 0
Newbie Poster
mailmarwa is offline Offline
1 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Board game c++
Next Thread in C++ Forum Timeline: Help A Newbie Sort





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC