tree deletion we now turn to the inverse problem of insertiondeletion our task is to define an algorithm for deletingi removing the node with key in tree with ordered keys unfortunatelyremoval of an element is not generally as simple as insertion it is straightforward if the element to be deleted is terminal node or one with single descendant the difficulty lies in removing an element with two descendantsfor we cannot point in two directions with single pointer in this situationthe deleted element is to be replaced by either the rightmost element of its left subtree or by the leftmost node of its right subtreeboth of which have at most one descendant the details are shown in the recursive procedure delete this procedure distinguishes among three cases there is no component with key equal to the component with key has at most one descendant the component with key has two descendants procedure delete (xintegervar pnode)(adens _deletion *procedure del (var rnode)begin if right nil then del( rightelse key : keyp count : countr : left end end delbegin (*delete*if nil then (*word is not in tree*elsif key then delete(xp leftelsif key then delete(xp rightelse (*delete ^:*if right nil then : left elsif left nil then : right else del( leftend end end delete the auxiliaryrecursive procedure del is activated in case only it descends along the rightmost branch of the left subtree of the element pto be deletedand then it replaces the relevant information (key and countin pby the corresponding values of the rightmost component rof that left subtreewhereafter rmay be disposed we note that we do not mention procedure that would be the inverse of newindicating that storage is no longer needed and therefore disposable and reusable it is generally assumed that computer system recognizes disposable variable through the circumstance that no other variables are pointing to itand that it therefore can no longer be referenced such system is called garbage collector it is not feature of programming languagebut rather of its implementations in order to illustrate the functioning of procedure we refer to fig consider the tree ( )then delete successively the nodes with keys the resulting trees are shown in fig ( -