
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
Question
Code those parts only in c++ where it says "code here"
1. Implement the minimum method for binary search trees.
2. Implement the maximum method for binary search trees.
3. Implement the delete method for binary search trees. In the case where the node to be removed has two children, search the right subtree for a replacement value. Do not forget to update the size of the tree when appropriate (including for insertion).
4. Implement the in-order traversal method for binary search trees.
5. Implement the post-order traversal method for binary search trees.
Code is here BST.cpp
#include<iostream>
#include <vector >
#include <limits.h>
#include "BST.h"
using namespace std;
BST::BST()
{
***********code here**********
}
BST::~BST()
{
***********code here**********
}
//returns the address of the target node (if found)
Node* BST::search(int target)
{
returnsearch(root,target);
}
//method to search for target value in BST
//If node is not present we will return null
Node* BST::search(Node* n, int target)
{
//Tree is empty or value is not found
if (n == nullptr) //if root node is null just return null value
{
returnnullptr;
}
// Value is found
elseif (n->value == target)
{
returnn;
}
//If given valuen is not larger, traverse left.
elseif (n->value > target)
{
returnsearch(n->left, target);
}
//given value larger than current value, traverse right
elseif (n->value < target)
{
returnsearch(n->right, target);
}
//else if target is equal to root node just return the root node i.e n.
returnn;
}
Node* BST::minimum()
{
***********code here**********}
Node* BST::minimum(Node* n)
{
***********code here**********
}
Node* BST::maximum()
{
***********code here**********
}
Node* BST::maximum(Node* n)
{
***********code here**********}
Node* BST::insertValue(Node* n, int val)
{
//if root node is null
if (n == NULL) {
returnnewNode(val);
}
//if val<root's data insert in left half
if( n->value ==val) {
returnn;
}
//if val>root's data insert in right half
elseif (val > n->value) {
n->right = insertValue(n->right, val);
}
//if root's data is equal to val
elseif (val < n->value) {
n->left = insertValue(n->left, val);
}
//return the root node
returnn;
}
void BST::deleteValue(int val)
{
***********code here**********}
Node* BST::deleteValue(Node* n, int val)
{
***********code here**********
}
//this function uses isBST(root,low,high) as helper function
//to check for binary search tree.
bool BST::isBST(Node* n){
//These low and high are the min. and max. permitted values
//for a particular node
returnisBST(n, INT_MIN, INT_MAX);
}
//Pass low as INT_MIN and high as INT_MAX because
//root of the tree can take any value.
bool BST::isBST(Node* n, int low, int high){
// if n is null , then it is tree
if (n == NULL)
returntrue;
// left child value greater then its root
// then it is not BST
if (n->left != NULL && n->left->value > n->value)
returnfalse;
// rightt child value less then its root
// then it is not BST
if (n->right != NULL && n->right->value < n->value)
returnfalse;
// recursive calling
return (isBST(n->left,low,high) || isBST(n->right, low, high));
}
//preOrder traversal method
void BST::preOrder(Node* n, vector<Node*> &order){
if (n)
{
// Root l R
order.push_back(n); // push node's address
preOrder(n->left, order); // Call on node->left i.e left subtree
preOrder(n->right, order); // Call on node->right i.e right subtree
}
}
void BST::inOrder(Node* n, vector<Node*> &order)
{
***********code here**********
}
void BST::postOrder(Node* n, vector<Node*> &order)
{
***********code here**********
}
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 2 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
- In c++ pleasearrow_forwardC++ DATA STRUCTURES: How do I solve this red black treearrow_forwardIN JAVA LANGUAGE FILL OUT THE FIND MAX FUNCTION public int findMax();/* Returns the largest element in the tree.* This method should call upon the recursive findMax_r() you write.** @return the largest element in the tree (an int value)* Example: findMax() will return 29 for the tree below** (28)* / \* (14) (29)* /* (1)*/ DO THIS BY CALLING A RECURSIVE FUNCTION SHOULD RETURN LARGEST ELEMENT IN A BST THANK YOU!!!!!arrow_forward
- Help in C++ please: Write a program (in main.cpp) that: Prompts the user for a filename containing node data. Outputs the minimal spanning tree for a given graph. You will need to implement the createSpanningGraph method in minimalSpanTreeType.h to create the graph and the weight matrix. There are a few tabs: main.cpp, graphType.h, linkedList.h, linkedQueue.h, queueADT.h, minimalSpanTreeType.h, and then two data files labeled: CH20_Ex21Data.txt, CH20Ex4Data.txtarrow_forwardIn C++, – Implement a Priority queue using a SORTED list. Use Quick sort after adding a new node. Create a class called Node: Have a Name and Priority.Data set - 1 is the highest priority, 10 is lowest priority.Enqueue and dequeue in the following order.Function Name, PriorityEnqueue Joe, 3Enqueue Fred, 1Enqueue Tuyet, 9Enqueue Jose, 6DequeueEnqueue Jing, 2Enqueue Xi, 5Enqueue Moe, 3DequeueEnqueue Miko, 7Enqueue Vlady, 8Enqueue Frank, 9Enqueue Anny, 3DequeueEnqueue Xi, 2Enqueue Wali, 2Enqueue Laschec, 6Enqueue Xerrax, 8DequeueDequeueDequeueDequeueDequeueDequeueDequeueDequeueDequeueDequeueDequeuearrow_forwardGiven the following text file (tree.txt), load the data into a binary search tree representation in Python Implement a method to calculate the height of the tree from the root (iterative or recursive) The image attached to this question should be rendered as the file "tree.txt"arrow_forward
- Write a C++ code to insert the following numbers in two Binary Search Trees. Insert numbers of first list in Binary Search Tree#1, and numbers of second list in Binary Search Tree#2. Do not insert both lists in a single Binary Search Tree. List#1. 5, 78, 45, 23, 11, 89, 10, 78, 6, 99, 876, 5, 67, 13 List#2. 5, 89, 688, 52, 557, 953, 5, 7, 55, 35, 89, 99, 99, 6, 557, 89, 5, 99, 6, 2, 45, 12, 7, 6, 94, 93, 99, 67 After inserting numbers in Binary Search Trees. Write a function to print only those numbers that appear in List#1 and more than 2 times in List#2. For example, the number “5” appears in List#1 and 3 times in List#2. So your code should print “5” and similar other numbers.arrow_forwardRewrite the definition of the function searchNode of the class B-tree provided (bTree.h) by using a binary search. Write a C++ code to ask the user to enter a list of positive integers ending with -999, build a b- tree of order 5 using the positive integers, and display the tree contents. Also, ask the user to enter a number to search and display if the number is found in the tree. bTree.harrow_forwardJava Programming language Please help me with this. Thanks in advance.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