title: Can somebody explain me this Binary tree transplant algorithm?
body: <p>I found this algorithm in a textbook and I'm not sure I understand it.</p>
  
  <pre><code>TRANSPLANT(T,u,v){
    1 if u.p == NIL
    2   T.root = v
    3 else if u == u.p.left
    4   u.p.left=v
    5 else u.p.right == v
    6 if v != NIL
    7   v.p=u.p
  }
  </code></pre>
  
  <p>Also, what do you think is <code>p</code> inside the node?</p>
  
  <p>Why can't he just compare the node with the node?</p>
  
  <p>Notes from textbook:</p>
  
  <blockquote>
    <p>In order to move subtrees around within the binary search tree, we define a
    subroutine <code>TRANSPLANT</code>, which replaces one subtree as a child of its parent with
    another subtree. When <code>TRANSPLANT</code> replaces the subtree rooted at node <code>u</code> with
    the subtree rooted at node , node <code>u</code>'s parent becomes node ’s parent, and <code>u</code>'s
    parent ends up having  as its appropriate child.</p>
  </blockquote>