C++ implementation
Return the number of nodes in a binary search tree that are
greater than the amount that the user enters.
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int data;
vector<Node*> child;
};
Node* newNode(int data)
{
Node* temp = new Node;
temp->data = data;
return temp;
}
int nodesGreater(Node* root, int search)
{
if (root == NULL)
return 0;
int count = 0;
if(root->data > search)
count++;
int numNodes = root->child.size();
for (int i = 0; i < numNodes; i++)
{
Node* child = root->child[i];
count += nodesGreater(child, search);
}
return count;
}
int main()
{
Node* root = newNode(5);
(root->child).push_back(newNode(6));
(root->child).push_back(newNode(3));
(root->child).push_back(newNode(4));
(root->child[0]->child).push_back(newNode(22));
(root->child[1]->child).push_back(newNode(17));
(root->child[1]->child).push_back(newNode(9));
(root->child[2]->child).push_back(newNode(8));
cout << "\nDemo Binary search tree has been constructed." << endl;
int search;
cout << "Please enter an integer to search: ";
cin >> search;
int nNodesGreater = nodesGreater(root, search);
if(nNodesGreater == 0)
cout << "Sorry, there are no nodes greater than " << search << endl;
else
cout << "Number of nodes greater than " << search << " are = " << nNodesGreater << endl;
return 0;
}
********************************************************** SCREENSHOT ******************************************************

C++ implementation Return the number of nodes in a binary search tree that are greater than...
A Binary Search Tree is a binary tree where nodes are ordered in the following way: each node contains one key (also known as data) the keys in the left subtree are less than the key in its parent node the keys in the right subtree are greater than the key in its parent node duplicate keys are not allowed Create a Binary Search Tree inserting the following list of numbers in order from left to right. 10, 6, 4, 8, 18, 15, 21 Please type...
The linked implementation is used in the coding of a Binary Search Tree structure. Calculate the structure's density assuming that it contains 200 nodes and: a. Each node contains 10 bytes of information. b. Each node contains 300 bytes of information. Then, repeat the above exercise for the array implementation of the Binary Search Tree, assuming it is: a. Left balanced. b. Skewed to the right.
C++ Write a function, singleParent, that returns the number of nodes in a binary tree that have only one child. Add this function to the class binaryTreeType and create a program to test this function. (Note: First create a binary search tree.)
C++ ONLY Threaded Binary Search Tree Since a binary search tree with N nodes has N + 1 NULL pointers, half the space allocated in a binary search tree for pointer information is wasted. Suppose that if a node has a NULL left child, we make its left child pointer link to its inorder predecessor, and if a node has a NULL right child, we make its right child pointer link to its inorder successor. This is known as a...
Show that the tree height of a height-balanced binary search tree with n nodes is O(log n). (Hint: Let T(h) denote the fewest number of nodes that a height-balanced binary search tree of height h can have. Express T(h) in terms of T(h-1) and T(h-2). Then, find a lower bound of T(h) in terms of T(h-2). Finally, express the lower bound of T(h) in terms of h.)
(C++ Psuedocode) A pair of nodes x, y in a (supposed) binary search tree violate the BST property if x is an ancestor of y, and the corresponding values are “out of order”. Given a BST, find the number of pairs that violate the BST property.
A binary search tree includes n nodes and has an height h. Check all that applies about the space complexity of TREE-MINIMUMX) TREE-MINIMUM () 1 while x. left NIL 2 3 return x x x.left O it is e (lg n) ■ it is 0(h). D it is e (1) ■ It is in place ■ it is Θ (n) A binary search tree includes n nodes and has an height h. Check all that applies about the space complexity...
Write a C++ program that implements a binary search tree (BST) to manage a number of integer items with different priorities. In order to do so, you will need to maintain a queue as an item in the tree. Each queue item is an integer. All items in a given queue will have the same priority. As a new item with a user-specified priority comes in, it should be enqueued in the queue with items of that priority. A new...
Binary Search tree Implementation of a BST class that include the following operations: - Insertion, Search, Deletion - Traversals: Inorder, Preorder, Postorder using c++
Data Structures and Algorithms What is the: a. maximum number of levels that a binary search tree with 100 nodes can have? b. minimum number of levels that a binary search tree with 100 nodes can have? c. maximum total number of nodes in a binary tree that has N levels? (Remember that the root is level 0.) d. maximum number of nodes in the Nth level of a binary tree? e. number of ancestors of a node in the...