Question: Consider the following implementation of the contains method. How does it differ from the one we showed in Section 17.4 ? Is it better or

Consider the following implementation of the contains method. How does it differ from the one we showed in Section 17.4 ? Is it better or worse, and why?

private boolean contains (IntTreeNode root, int value) { if (root = null) ( return false; } else if (value == root.data) { return true; } else { return contains (root.left, value) || contains (root.right, value);

private boolean contains (IntTreeNode root, int value) { if (root = null) ( return false; } else if (value == root.data) { return true; } else { return contains (root.left, value) || contains (root.right, value);

Step by Step Solution

3.50 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This second version of contains is much less efficient than the on... View full answer

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 Building Java Programs A Back to Basics Approach Questions!