Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise, you will be writing a function that counts the number of times

ID: 3738436 • Letter: I

Question

In this exercise, you will be writing a function that counts the number of times a given value occurs in a binary search tree. Assume that in our tree, if the same value is inserted more than once, subsequent copies go to the right of the original.

Download and study the files BSTcomplete.h, which contains an implementation of a Binary Search Tree along with the operations we have studied in class, finalBST.cpp, which is a program that inserts some values into an empty tree and calls the occurrencesfunction on some value, in order to determine how many times it appears in the tree. The file where you need to implement your occurrencesfunction is BSTOps.h

Long story short, make it so that finalBST.cpp compiles and runs, and that it produces the expected output. Uploaf your modified BSTOps.h file here.

finalBST.cpp

BSTOps.h

Explanation / Answer

int occurrences(Node* root, int value)
{
    if (root == NULL)
        return 0;
    if (root->data == value) {
        return 1 + occurrences(root->right, value) + occurrences(root->left, value);
    }
    else if (value< root->data) {
        return occurrences(root->left, value);
    }
    else {
        return occurrences(root->right, value);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote