Question: ( 1 Java Program ) : Given the two binary trees. Write a method called swapSubtrees, which swaps all of the left and right subtrees
Java Program: Given the two binary trees. 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 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 trees given in the above. Add this
method to the class BinaryTree and create a program to test this method.
Note: To test your algorithm, first create a binary search tree.
Start with an empty heap, and enter ten items with priorities through
Draw the resulting heap.
Remove three entries from the heap you created in the above
exercise. Draw the resulting heap.
Lab Tree Directions
Problem #:
a Create a TreeNode class with the following methods: default constructor, two
overloaded constructors, copy constructor, getValue, getLeft, getRight, setValue,
setLeft, setRight
b Create a BTInterface with the following abstract methods: getRoot, setRoot,
isEmpty, swapSubtrees, singleParent preorder, postOrder, inOrder, insert
c Create an abstract Binary Tree 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 Treebemo class that creates two BinarySearchTree objects. Use default and
overloaded constructors. For tree one: call the methods make Tree makes a complete
tree print Treet swapSubtrees, print Tree. Simliar for tree two. Also, print out the
number of single parents in each tree. Define makeTree and print Tree in this class.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
