Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with the following Algorithm problem in pseudo code Let T be a bi

ID: 3884774 • Letter: P

Question

Please help me with the following Algorithm problem in pseudo code

Let T be a binary search tree with n nodes. Each node consists of the fields: parent, left, right and item as a pair of (key, element). Complete a remove(k) algorithm that remove a node of key k in BST in a pseudo code. To complete remove(k), give the following sub-algorithms in the pseudo codes, which are required to execute remove(k):

Search(k, v): return a node of key k in a tree rooted at v.

removeAboveExternal(w): remove an external node w and its parent node v, then reconnect v’s parent with w’s sibling.

Successor(v) : find a node of immediate successor of a node v.

isExternal(v): test whether a node v is an external node.

isRoot(v): test whether a node v is the root of tree.

Any other required sub-algorithms if you need.

This is what i have so far: its not in pseudo code type

Case 1: If it has no children

            If (nodeKRemove.left==null && nodeKRemove.right==null

                        If(nodeKRemov.left.data==nodeK.data

                                    nodeKRemove.left=null          

                                    nodeKRemove=null

                                    success true

else if (nodeKRemove.right.data==nodeK.data

            nodeKRemove.right=null

            nodeKRemove=null

            success=true

            return success

Case 2: if it only has one children

Else if (nodeKRemove.left==null && nodeKRemove.right !=null || nodeKRemove.right==null && nodeKRemove.right!=null

            If (nodeKRemove.left!=null

                        nodeKRemove=nodeK.left

                        nodeK=null

                        success=true;

                        return success

           

            else if (nodeKRemove.right != null

                        nodeKRemove.right=null

                        success=true;

                        return true;

Case 3: if it has 2 children

If (nodeKRemove.left!=null && nodeKRemove.right !=null)

            Node minLeftNode== findTheLeftMostNodeFromtheRightSubTree(nodeToRemove.right);

            }

Explanation / Answer

If (nodeKRemove.left==null && nodeKRemove.right==null

                        If(nodeKRemov.left.data==nodeK.data

                                    nodeKRemove.left=null          

                                    nodeKRemove=null

                                    success true

else if (nodeKRemove.right.data==nodeK.data

            nodeKRemove.right=null

            nodeKRemove=null

            success=true

            return success

If (nodeKRemove.left!=null

                        nodeKRemove=nodeK.left

                        nodeK=null

                        success=true;

                        return success

           

            else if (nodeKRemove.right != null

                        nodeKRemove.right=null

                        success=true;

                        return true;