Implement the simplified heap class for integers

Assignment Help C/C++ Programming
Reference no: EM132136223

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding of the recursive algorithm, by comparing it with Algorithms 3.4.15 and 3.4.16 from page 128 to 130. Are they equivalent?

template <class T>
class Node {
public:
T value;
Node *left;
Node *right;

Node(T val) {
value = val;
left = NULL;
right = NULL;
}

Node(T val, Node<T> left, Node<T> right) {
value = val;
left = left;
right = right;
}
};

template <class T>
class BST {

private:
Node<T> *root;
intheightHelper(Node<T> *root) {
if (!root) return 0;
else return 1 + max(heightHelper(root->left), heightHelper(root->right));
}
bool deleteValueHelper(Node<T>* parent, Node<T>* current, T value) {
if (!current) return false;
if (current->value == value) {
if (current->left == NULL || current->right == NULL) {
Node<T>* temp = current->left;
if (current->right) temp = current->right;
if (parent) {
if (parent->left == current) {
parent->left = temp;
} else {
parent->right = temp;
}
} else {
this->root = temp;
}
} else {
Node<T>* validSubs = current->right;
while (validSubs->left) {
validSubs = validSubs->left;
}
T temp = current->value;
current->value = validSubs->value;
validSubs->value = temp;
return deleteValueHelper(current, current->right, temp);
}
delete current;
return true;
}
return deleteValueHelper(current, current->left, value) ||
deleteValueHelper(current, current->right, value);
}


public:
void add(T val) {
}

// print items in ascending order
void print() {
}

intnodesCount() {

}

intheight() {
return heightHelper(this->root);
}

bool deleteValue(T value) {
return this->deleteValueHelper(NULL, this->root, value);
}
};

Then test it with the following list of last names in our class:
intmain() {
constsize_tarraySize{17};
array <string, arraySize>names{"Taylor", "Tian", "Wheeler",
"Wilmot", "Hoffmann", "Fall", "Kline", "Aparicio",
"Li", "Hess", "Stenseng", "Weiss", "Hood", "Christiansen",
"Dale", "Seward", "Han"};

BST<string> *bst = new BST<string>();

for(size_ti{0}; i<names.size(); ++i)
bst->add(names[i]);
bst->print();
cout<<endl;
cout<<"Nodes count: "<<bst->nodesCount();
cout<<endl;
cout<<"Height: "<<bst->height();
cout<<endl;

bst->deleteValue("Tian");
cout<<"Tian removed: ";
bst->print();
cout<<endl;

bst->deleteValue("Kline");
cout<<"Kline removed: ";
bst->print();
cout<<endl;

return 0;
}

2. Implement the simplified Heap class for integers, in C++. Refer to the algorithms in the textbook.

The required methods are:
- Siftdown (algorithm 3.5.7)
- heapify (algorithm 3.5.12)
- print (to print the array of integers)
Test your heap's heapify method,using the following sequence of integers as initial status of the array.Display the before and after status.
42, 58, 11, 33, 81, 65, 32, 19, 24, 57, 13, 47, 66, 41, 95

Verified Expert

The solution file is prepared in ms word and implementation done it in dev c++ . This solution has twos files are bst.cpp and heap.cpp. The bst file implemented binary search tree algorithm using recursive method in delete node operation and insert node. The insert node can be vector string and performed delete node , compared 2 algorithms for node do not have child and node have two children. The second file implemented heap sort with heapify and sift algorithm to sort array. The output of the programs are attached in the solution.

Reference no: EM132136223

Questions Cloud

Explaining employee vs. independent contractor : You will write a paper explaining employee vs. independent contractor classifications using the Madrid and Berne case scenario provided below.
Staff cutbacks because of declining profits : A paper manufacturer is forced to make staff cutbacks because of declining profits. It decides to cut back each employee's hours and pay by one-half day
Evaluate google diversification into new products : Evaluate Google's diversification into new products and businesses. With particular reference to (a) video sharing (You Tube), (b) browsers (Chrome)
Perceptions to match objective reality : Leaders who recognize perceptual distortions can adjust their perceptions to match objective reality?
Implement the simplified heap class for integers : Implement the simplified Heap class for integers, in C++. Refer to the algorithms in the textbook - Implement the Binary Search Tree
Formulate a linear programming model : Introduction to Math Programming - Formulate a linear programming model for the following description. What do you observe about the solution
Successful or not in the organization : What factors determine whether teams are successful or not in the organization?
Do you agree or disagree with his conclusions : Do you agree or disagree with his conclusions? Can goals of a business sometimes conflict with the goals of society and/or a community?
Implications of generational differences in the workforce : What are the implications of generational differences in the workforce? What strategies should companies consider from a training

Reviews

inf2136223

11/26/2018 11:35:42 PM

I got a perfect essay that made me score 9/10 in the assessment exam and it will surely enhance my grades that I had degraded in the previous exam due to incorrect and late submission of the assignment. But this time since it was done by your perfect tutors I was expecting some good marks and hurray I got it. Thanks to you dear team.

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd