Question: Java Problem (binary tree) A structure similar to a linked list is a binary tree. Instead of each node pointing to one following node, it

Java Problem (binary tree)

A structure similar to a linked list is a binary tree. Instead of each node pointing to one following node, it may point to two. A simple implementation of node for a binary tree is shown below. For this question, you are to implement a method called getSize that takes rst node in a binary tree (its root) and returns the number of nodes in the tree. publ i c c l a s s BinaryNode { p r i v a t e BinaryNode l e f t , r i g h t ; p r i v a t e T element ; publ i c BinaryNode (T elem) { l e f t = r i g h t = n u l l ; element = elem ; } publ i c BinaryNode g e tLe f t ( ) { r e turn l e f t ; } publ i c void s e tLe f t (BinaryNode node ) { l e f t = node ; } publ i c BinaryNode ge tRight ( ) { r e turn r i g h t ; } publ i c void s e tRight (BinaryNode node ) { l e f t = r i g h t ; } publ i c T getElement ( ) { r e turn element ; } publ i c void setElement (T elem) { element = elem ; } } 1. Using the fantastic four approach, determine the size n problem for the method getSize. [1 point] 2. Identify the stopping condition(s) and the return value, if any, for the problem. [1 point] 3. Determine the size m problem(i.e. the subproblem) for the problem. [1 point] 4. How is the size-n problem constructed from the size m problem? [1 point] 5. Implement the method public static int getSize(BinraryNode node) [4 points]

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!