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

insertBSTDup() will insert an object into a binary search tree and will take spe

ID: 3719668 • Letter: I

Question

insertBSTDup() will insert an object into a binary search tree and will take specific action on duplicate objects being inserted into the binary search tree. The specific action taken will be defined within the operate() method implented in the class of objects being inserted into the binary search tree. Describe the use of the operate() method.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public interface TreeComparable {

public int compareTo(Object o);

public void operate(Object o);

public void visit();

}

Explanation / Answer

Some BSTs may choose to allow duplicate values, HENCE IT DEPENDS ON WHAT Design you are following


1) IF IT DOES NOT ALLOW Duplicates
=> The just return the root as we dont have to insert dupliccate. Basically do not do anything

2) IF IT ALLOW Duplicates
=> Then follow one rule of inserting The duplicate node
a) Always to the right
b) Always to the left  
We can choose wither a) or b)