Question: In Java. Thank you. Given the two binary trees below: Write a method called swapSubtrees, which swaps all of the left and right subtrees in

In Java. Thank you.

Given the two binary trees below: Write a method called swapSubtrees, which swaps all of the left and right subtrees in the above binary trees. Add this method to the class Binary Tree and create a program to test this method for these 2 trees. Show the original trees and the resulting trees. Write a method called singleParent, which returns the number of nodes in a binary tree that have only one child for the 2 trees given in the above. Add this method to the class BinaryTree and create a program to test this method. To test your algorithm, first create a binary search tree.

Create a TreeNode class with the following methods default constructor, two overloaded constructors, copy constructor. get Value. getLeft. getRight. set Value. setLeft. setRight b) Create a BTlnterfoce with the following abstract methods getRoot, setRoot, isEmpty, swapSubtrees. singleParent. preorder. postOrder, inOrder, insert c) Create an abstract BinaryTree class that implements the interface. Include the default constructor, a private helper method called checkNode for singleParent() and toString Make insert an abstract method. d) Derive a BinarySearchTree class from Binary Tree with the following methods default constructor, overloaded constructor (use a variable length parameter), insert, e) Create a TreeDemo class that creates two BinarySearchTree objects. Use default and overloaded constructors. For tree one call the methods make Tree (makes a complete tree), print Tree wapSubtrees. print Tree Similar for tree two. Also, print out the number of single parents in each tree. Define make Tree and print Tree in this class.

 In Java. Thank you. Given the two binary trees below: Writea method called swapSubtrees, which swaps all of the left and right

1. Given the two binary trees below: 14 4 15 18 16) (20 17 7 4 5 Write a method called swapSubtrees, which swaps all of the left and right subtrees in the above binary trees. Add this method to the class BinaryTree and create a program to test this method for these 2 trees. Show the original trees and the resulting trees. Note: To test your algorithm, first create a binary search tree. Write a method called singleParent, which returns the number of nodes in a binary tree that have only one child for the 2 trees given in the above. Add this method to the class Binary Tree and create a program to test this method. Note: To test your algorithm, first create a binary search tree

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!