Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.ArrayList; public class BinarySearchTree { Node root; public BinarySearchTree ( ) { this.root = null; } public BinarySearchTree ( Node p ) { this.root
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
above is the snipet of code that I need help on
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