Consider the following implementation of depth within the Node class: public int
ID: 3728137 • Letter: C
Question
Consider the following implementation of depth within the Node class: public int depthO f int leftDepth = 0; if (left != null) leftDepth= left.dept hO: int rightDepth e: if (right != null) rightDepth= right .d epth); return Math.max (leftDepth, rightDepth); // returns the bigger of the two Note that the method does not include +1 in the return statement, as it should Consider running it on the root of the following tree: What value would this version of depth return and why? Note that the array "B "A "D "C "E" would generate this tree if added in order to an empty tree.) 2, because the actual depth is 3 and we are returning 1 less than what depth should return O O 2, because the depth of D is 2 and it is deeper than A 1. because the left depth is 1 and we return left Depth O 0, because we never add anything to leftDepth or rightDepth which start as 0Explanation / Answer
0 will be returned as output since we are just calling the function without adding any value to it..Once the stack gets completed it returns the max of left depth and right depth which will be both zero only.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.