Question: JAVA Recursively complete the removeSingles() method for a binary tree.One helper function must be used. public class MyIntSET { private Node root; private static class

JAVA Recursively complete the removeSingles() method for a binary tree.One helper function must be used.

public class MyIntSET {

private Node root;

private static class Node {

public final int key;

public Node left, right;

public Node(int key) { this.key = key; }

}

// remove all nodes that have only one child by "promoting" that child

// repeat this recursively as you go up, so the final result should have no nodes with only one child

// if you start with "41", the tree is unchanged.

// if you start with "41 21 61", the tree is unchanged.

// if you start with the BST "41 21 11 1", then the result is the tree "1"

// if you start with the BST "41 21 61 11", then the result is the tree "41 11 61"

// Hint: This requires that you check for "singleness" after the recursive calls

public void removeSingles() {

// TODO

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!