Answered step by step
Verified Expert Solution
Link Copied!

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

I'm 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 I'm 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 BinarySearchTree(Node p){
this.root = p;
}
public boolean isEmpty(){
/**
* check if the tree is empty
* @return true for yes, false for no
*/
}
public boolean isValid(Node 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 setRoot(Integer e){
/**
* if tree does not have a root, create root node using e and return true, otherwise, return false
*/
}
public int size(Node start){
/**
* count and return the number of nodes in the tree rooted at start
*/
}
public int depth(Node target){
/**
* count and return the depth of node target
*/
}
public int height(Node start){
/**
* find and return the height of tree or subtree rooted at start
*/
}
public Node parent(Node 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 numChildren(Node target){
/**
* return the number of children for the node referred by target
*/
}
public boolean isInternal(Node target){
/**
* check if a node target is an Internal node, return true for yes, false for No
*/
}
public boolean isExternal(Node 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions