Removal of the binary tree knot



  • There's a binary tree, we need to remove the element.
    We found the option to remove the element and place it either the right element of its left support or its left-handed right support.
    Question: How is it best to organize?
    It is logical that the replacement element should specify the support signs and the owner should replace the indicator with NULL, with the owner of the removed element replacing the index with the replacement element.
    If you do anything in the forehead, you need two support indicators, parents ' indexes and indicators for the elements themselves.
    Is there any right way to remove this hemore? Probably more streamlined.

    Please see my code line 164, the function is not blinking, but it's kind of well written.



  • In the case of a binary tree, I recommend that the correct algorithm be seen in Cormen (sighs)"Algorithms. Building and analysis." page 326 or in a simpler and more visible version http://www.tech-faq.com/binary-tree-deleting-a-node.html

    In both cases, a classic storage data structure is used BSTin which the element is presented to the (parent, left, right, data)


    In the case of a conventional binary tree, only the situation where the deleted element of the reference left and right - No. null♪ In this situation, there is a need to round the tree side by side. left or rightfind the first possible leaf in a tree and Replace the removed element with that sheet.

    An additional field may be stored in each tree hub to optimize the operation leafwhich would indicate such a possible leaf to avoid the passage through the tree branch in the event of removal of the element. Although, I believe, interest in such optimization is strictly theoretical.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2