
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
package chapter07;
public class BSTNode
{
private int info;
private BSTNode left;
private BSTNode right;
public BSTNode(int info)
{
this.info = info;
this.left = null;
this.right = null;
}
public void setInfo(int info)
{
this.info = info;
}
public int getInfo()
{
return this.info;
}
public void setRight(BSTNode right)
{
this.right = right;
}
public BSTNode getRight()
{
return this.right;
}
public void setLeft(BSTNode left)
{
this.left = left;
}
public BSTNode getLeft()
{
return this.left;
}
}
package chapter07;
public class BinarySearchTree
{
protected BSTNode root;
protected boolean success;
public BinarySearchTree()
{
this.root = null;
}
public boolean contains(int value)
{
BSTNode curr = root;
while(curr != null)
{
if(value == curr.getInfo())
{
return true;
}
else if(value < curr.getInfo())
{
curr = curr.getLeft();
}
else
{
curr = curr.getRight();
}
}
return false;
}
public boolean add(int value)
{
root = add(value, root);
return success;
}
private BSTNode add(int value, BSTNode curr)
{
if(curr == null)
{
curr = new BSTNode(value);
success = true;
}
else if(value < curr.getInfo())
{
curr.setLeft(add(value, curr.getLeft()));
}
else if(value > curr.getInfo())
{
curr.setRight(add(value, curr.getRight()));
}
else
{
success = false;
}
return curr;
}
public void preOrder()
{
System.out.print("Pre Order: ");
preOrder(root);
System.out.println();
}
private void preOrder(BSTNode curr)
{
if(curr != null)
{
System.out.print(curr.getInfo() + " ");
preOrder(curr.getLeft());
preOrder(curr.getRight());
}
}
public void inOrder()
{
//Complete this method as required in the homeowrk instructions
}
public void postOrder()
{
//Complete this method as required in the homeowrk instructions
}
public int countLeaves()
{
//Complete this method as required in the homeowrk instructions
}
public int size()
{
//Complete this method as required in the homeowrk instructions
}
public int height()
{
//Complete this method as required in the homeowrk instructions
}
public boolean remove(int target)
{
root = remove(target, root);
return success;
}
private BSTNode remove(int target, BSTNode curr)
{
if(curr == null)
{
success = false;
}
else if(target < curr.getInfo())
{
curr.setLeft(remove(target, curr.getLeft()));
}
else if(target > curr.getInfo())
{
curr.setRight(remove(target, curr.getRight()));
}
else
{
curr = removeNode(curr);
success = true;
}
return curr;
}
private BSTNode removeNode(BSTNode curr)
{
if(curr.getLeft() == null)
{
return curr.getRight();
}
else if(curr.getRight() == null)
{
return curr.getLeft();
}
else
{
int data = getRightMostData(curr.getLeft());
curr.setInfo(data);
curr.setLeft(remove(data, curr.getLeft()));
return curr;
}
}
private int getRightMostData(BSTNode subtree)
{
BSTNode temp = subtree;
while (temp.getRight() != null)
{
temp = temp.getRight();
}
return temp.getInfo();
}
}

Transcribed Image Text:Look for BSTNode.java and BinarySearch Tree.java
BinarySearch Tree.java class contains the methods completed
few additional methods.
You are required to complete the following method
for binarysearchtree.java
and
countLeaves (): The method doesn't take any parameters and returns an
int, the method returns the number of leaves in the Binary Search Tree.
-size(): The method doesn't take any parameters and returns an int, the
method returns the nodes in the Binary Search Tree.
inOrder (): The method doesn't take any parameters and doesn't return
any value, the method displays the values stored in the BST using an In
Order traversal.
postOrder (): The method doesn't take any parameters and doesn't
return any value, the method displays the values stored in the BST using a
Post Order traversal.
height(): The method doesn't take any parameters and returns an int,
the method returns the height of the Binary Search Tree.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- public class Plant { protected String plantName; protected String plantCost; public void setPlantName(String userPlantName) { plantName = userPlantName; } public String getPlantName() { return plantName; } public void setPlantCost(String userPlantCost) { plantCost = userPlantCost; } public String getPlantCost() { return plantCost; } public void printInfo() { System.out.println(" Plant name: " + plantName); System.out.println(" Cost: " + plantCost); }} public class Flower extends Plant { private boolean isAnnual; private String colorOfFlowers; public void setPlantType(boolean userIsAnnual) { isAnnual = userIsAnnual; } public boolean getPlantType(){ return isAnnual; } public void setColorOfFlowers(String userColorOfFlowers) { colorOfFlowers = userColorOfFlowers; } public String getColorOfFlowers(){ return colorOfFlowers; } @Override public void printInfo(){…arrow_forwardUML for the following Code: public class ProductOrder { private int numBook = 0; private int numCD = 0; private int numDVD = 0; public ProductOrder(int numBook, int numCD, int numDVD){ this.numBook = numBook; this.numCD = numCD; this.numDVD = numDVD; } public int getBook(){ return numBook; } public void setBook(int numBook){ this.numBook = numBook; } public int getCD(){ return numCD; } public void setCD(int numCD){ this.numCD = numCD; } public int getDVD(){ return numDVD; } public void setDVD(int numDVD){ this.numDVD = numDVD; } public int getProductTotal(){ return getBook() + getCD() + getDVD(); } }arrow_forwardpublic class Course { private String courseNumber, courseTitle; public Course() { } public Course(String courseNumber, String courseTitle) { this.courseNumber = courseNumber; this.courseTitle = courseTitle; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseTitle(String courseTitle) { this.courseTitle = courseTitle; } public String getCourseNumber() { return courseNumber; } public String getCourseTitle() { return courseTitle; } public void printInfo() { System.out.println("Course Information: "); System.out.println(" Course Number: " + courseNumber); System.out.println(" Course Title: " +…arrow_forward
- Question 6 Consider: class Bike { } private String color; public Bike() { } public Bike(String newColor) { color = newColor; } public Bike (Bike bike) { color = } bike.color; public String getColor() { } } return color; public void setColor(String newColor) { color = newColor; Bike bike1= new Bike(); = Bike bike2 new Bike("blue"); Bike bike3 = new Bike(bike2); bike2.setColor("green"); Bike bike4 = new Bike(bike2); Which of the following are correct? bike4.getColor() returns null bike4.getColor() return "blue" bike3.getColor() return "green" bike2.getColor() returns "blue" bike4.getColor() return "green" bike1.getColor() returns bike3.getColor() return null bike3.getColor() returns "blue" bike2.getColor() returns "green" bike1.getColor() returns nullarrow_forwardGiven the following class: class bookType { public: void setBookTitle(string s); //sets the bookTitle to s void setBookISBN(string ISBN); //sets the private member bookISBN to the parameter void setBookPrice(double cost); //sets the private member bookPrice to cost void setCopiesInStock(int noOfCopies); //sets the private member copiesInStock to noOfCopies void printInfo() const; //prints the bookTitle, bookISBN, the bookPrice and the copiesInStock string getBookISBN() const; //returns the bookISBN double getBookPrice() const; //returns the bookPrice int showQuantityInStock() const; //returns the quantity in stock void updateQuantity(int addBooks); // adds addBooks to the quantityInStock, so that the quantity // in stock now has it original value plus the parameter sent to this function private: string bookName; string…arrow_forwardI have the following code: public class Length{ private int feet; private int inches; Length() { feet = inches = 0; } Length(int newFeet, int newInches) { feet = newFeet; inches = newInches; } public int getFeet() { return feet; } public void setFeet(int newFeet) { feet = newFeet; } public int getInches() { return inches; } public void setInches(int newInches) { inches = newInches; } public void add(Length otherLength) { int newFeet = this.feet + otherLength.feet; int newInches = this.inches + otherLength.inches; if(newInches >= 12) { newFeet++; newInches -= 12; } this.setFeet(newFeet); this.setInches(newInches); } public Length subtract(Length otherLength) { if(this.feet > otherLength.feet) { int newFeet = feet - otherLength.feet; int newInches = inches - otherLength.inches;…arrow_forward
- Object-oriented programmingProgram the employee class as indicated in the diagramTo calculate the salary, just multiply the number of hours by the payment per hour.The capture method asks the user for the data for the three attributes, asks for the hours worked and the payment per hour and with these data calculates the salary.The show method displays all of the employee's data.Do not forget the getter and setter methods only for attributes of type privateYour company has 7 employees and you would like1. Capture the data of each employee2. Show the data of each employee3. Show the data of a particular employee4. Calculate and display the average salary5. Calculate and display the name of the employee with the highest salary6. Calculate and display the name of the employee with the lowest salary7. Calculate and show the total payment you will make for all your employeesarrow_forwardclass smart { public: void print() const; void set(int, int); int sum(); smart(); smart(int, int); private: int x; int y; int secret(); }; class superSmart: public smart { public: void print() const; void set(int, int, int); int manipulate(); superSmart(); superSmart(int, int, int); private: int z; }; Now answer the following questions: a. Which private members, if any, of smart are public members of superSmart? b. Which members, functions, and/or data of the class smart are directly accessible in class superSmart?arrow_forwardIn C++ class bookType { public: void setBookTitle(string s); //sets the bookTitle to s void setBookISBN(string ISBN); //sets the private member bookISBN to the parameter void setBookPrice(double cost); //sets the private member bookPrice to cost void setQuantityInStock (int noOfCopies); //sets the private member quantityInStock to noOfCopies void printInfo() const; //prints the bookTitle, bookISBN, the bookPrice and the quantityInStock string getBookISBN() const; //returns the bookISBN double getBookPrice() const; //returns the bookPrice int showQuantityInStock() const; //returns the quantityInStock void updateQuantity(int addBooks); //adds addBooks to the quantityInStock, so that the quantity in stock now has it original value plus the parameter sent to this function private: string bookTitle; string bookISBN; double bookPrice; int quantityInStock; }; Write the full function definition for updateQuantity();arrow_forward
- Part 1 is already done and here it is public class Point { protected double x; protected double y; public Point() { } public Point(double x, double y) { this.x = x; this.y = y; } public double getX() { return x; } public double getY() { return y; } public void setPoint(Point X){ x = X.x; y = X.y; } void makeCopy(Point x){ setPoint(x); } Point getCopy(){ return this; } public void printPoint(){ System.out.println("["+this.x+", "+this.y+"]"); } @Override public String toString() { return "x-Coordinate is " + x + "and y-coordinate is " + y; } public boolean equals(Point X) {…arrow_forwardGiven the following class: class bookType { public: void setBookTitle(string s); //sets the bookTitle to s void setBookISBN(string ISBN); //sets the private member bookISBN to the parameter void setBookPrice(double cost); //sets the private member bookPrice to cost void setCopiesInStock(int noOfCopies); //sets the private member copiesInStock to noOfCopies void printInfo() const; //prints the bookTitle, bookISBN, the bookPrice and the copiesInStock string getBookISBN() const; //returns the bookISBN double getBookPrice() const; //returns the bookPrice int showQuantityInStock() const; //returns the quantity in stock void updateQuantity(int addBooks); // adds addBooks to the quantityInStock, so that the quantity // in stock now has it original value plus the parameter sent to this function private: string bookName; string…arrow_forwardIncorrect Question 4 Consider public class Species { } // fields private String name; private int population; private double growthRate; // constructor public Species () { } name = "No Name Yet"; population = 0; growthRate = 33.3; Which of the following is the best setter method for the population instance variable? public boolean setPopulation(int newPopulation) { } if (newPopulation>= 0) { } population = newPopulation; return false; } return true; public public void setPopulation (int newPopulation) if (newPopulation>= 0) { } population newPopulation; public void setPopulation (int newPopulation) { population } = newPopulation;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education