Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I ' m having a little trouble on my computer science homework. Our professor provided us with the outline of some code that we have
Im having a little trouble on my computer science homework. Our professor provided us with the outline of some code that we have to complete and Im having trouble figuring out how to do some of them. Here is a segment I was working that was giving me trouble:
import java.util.ArrayList;
public class BinarySearchTree
Node root;
public BinarySearchTree
this.root null;
public BinarySearchTreeNode p
this.root p;
public boolean isEmpty
check if the tree is empty
@return true for yes, false for no
public boolean isValidNode start
Given a binary tree, check if the tree is a binary search Tree
@return true for yes, false for no
if the node element is greater than leftchild and smaller than rightchild,
recursively check if its leftsubtree and rightsubtree are binary search tree
public boolean setRootInteger e
if tree does not have a root, create root node using e and return true, otherwise, return false
public int sizeNode start
count and return the number of nodes in the tree rooted at start
public int depthNode target
count and return the depth of node target
public int heightNode start
find and return the height of tree or subtree rooted at start
public Node parentNode start, Node target, Node parent
Given a tree or subtree rooted at start, find the target node and return its parent
recursion
if target is root, return base case
if start is null, return null
if start is target, return parent
if target element is smaller than start element, find parent on left subtree
if target element is greater than start element, find parent on right subtree
public int numChildrenNode target
return the number of children for the node referred by target
public boolean isInternalNode target
check if a node target is an Internal node, return true for yes, false for No
public boolean isExternalNode target
check if a node target is an external node, return true for yes, false for No
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started