Question
5.Given the binary search tree below, show the order that nodes are evaluated in searching for a value of 45. You do not need to
5.Given the binary search tree below, show the order that nodes are evaluated in searching for a value of 45. You do not need to include any node that is NULL. You must write your answer in the order that the nodes are evaluated. For example, Order of nodes visited: Node 15 means to evaluate the node with a value of 15 first.
6.
You have been given a recursive function to sum the values of all keys in a BST:
int findSum(TreeNode * root, int depth) {
if(root != NULL) {
int leftSum = findSum(root->left, depth + 1);
int rightSum = findSum(root->right, depth + 1);
cout key;
if (depth != 0)
{
cout}return leftSum + rightSum + root->key; } else return 0; }
Consider following binary search tree: 15 / \ 12 17 / 4 / \ 2 5 \ 8
The following code is called:
findSum(root, 0);
Root is a pointer to the TreeNode whose key is 15. What is the output from cout? Note that there is a single space between values that are printed to the terminal. Note, there are no intended errors in the code.
Given the binary search tree below, show the order that nodes are evaluated in searching for a value of 45. You do not need to include any node that is NULL. You must write your answer in the order that the nodes are evaluated. For example, Order of nodes visited: Node 15 means to evaluate the node with a value of 15 first. 15 60 30 70 20 50 40 45 Order of nodes visited: Node 15
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started