2. Assume that binary trees are implemented using a BinaryTreenode class that in
ID: 3734885 • Letter: 2
Question
2. Assume that binary trees are implemented using a BinaryTreenode class that includes the following fields and methods: // fields private T data; private BinaryTreenode left, right // methods public T getData() public BinaryTreenodecT> getLeft) public BinaryTreenodecT> getRight() ( return data; ( return left;) return rights public void setRight (BinaryTreenodecT> newR) right new; ) Write the findNegatives method whose header is given below. public static List findNegatives( BinaryTreenodecInteger> n) The method should return a list containing all the negative values in a binary tree containing Integer data. For example, if the tree pointed to by n looks like this: -6 45 9 8 1 7 -32 f indNogatvea (n) should return a list containing-6,-4.-1, and-3 (not necessarily in this order). If the same value appears more than once in the tree, it should also appear more than once in the result list. Part A: First, complete the English descriptions of the base and recursive cases, like what was given above for Question 1. o The list of negative values in an empty tree is the empty list. o The list of negative values in a tree with one node is (hill in your answer here) o The list of negative values in a tree with more than one node is (fill in your answer here) e findNegatives method. You may assume that the List used to hold negative values is implemented as an Part B: Now write th Arraylist.Explanation / Answer
A)
Base case: If n is null, return empty list
Recursive case: Add current data if it is negative, recursively add negative list from left subtree and right subtree
B)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.