1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergey [27]
2 years ago
10

Consider a binary search tree where each tree node v has a field v.sum which stores the sum of all the keys in the subtree roote

d at v.
(a) Modify the Insert operation (given below) to insert an element so that all the .sum fields of the tree are correct after applying the Insert operation. (Assume that all the .sum fields were correct before the Insert operation.) Your modified algorithm should take the same time as the original Insert operation. Explain your modification and give pseudo-code for the modified algorithm.

function Insert(T,z)

y <-- LocateParent(T,z)

z.parent <-- y

if (y = NIL) then T.root <-- z ;

else if (z.key< y.key) then y.left <-- z

else y.right <-- z

(b) Argue for the correctness of your algorithm. Explain why all the .sum fields are correct after running your modified Insert operation.

(c) Analyze the running time of your modified algorithm in terms of the size n and the height h of the binary search tree.
Computers and Technology
1 answer:
AVprozaik [17]2 years ago
6 0

Answer:

Each time you insert a new node, call the function to adjust the sum.

This method has to be called each time we insert new node to the tree since the sum at all the

parent nodes from the newly inserted node changes when we insert the node.

// toSumTree method will convert the tree into sum tree.

int toSumTree(struct node *node)

{

if(node == NULL)

return 0;

// Store the old value

int old_val = node->data;

// Recursively call for left and right subtrees and store the sum as new value of this node

node->data = toSumTree(node->left) + toSumTree(node->right);

// Return the sum of values of nodes in left and right subtrees and

// old_value of this node

return node->data + old_val;

}

This has the complexity of O(n).

Explanation:

You might be interested in
Is using abbreviations and symbols in social media a problem? Why or why not?
Ugo [173]
The correct answer is..A? 
5 0
3 years ago
When should you use the Reply All function when replying to an email
Dmitrij [34]
When the email was sent as a group email 

5 0
2 years ago
Read 2 more answers
What is the difference between an html opening tag and a closing tag?.
Doss [256]

Answer:

Explanation:

Generally speaking, there are two kinds of tags - opening tags: <html> and closing tags: </html>. The only difference between an opening tag and a closing tag is the forward slash "/". You label content by putting it between an opening tag and a closing tag.

HTML is all about elements.

7 0
1 year ago
In the Microsoft publisher application, words underlined in red are ____.
nydimaria [60]

In the Microsoft publisher application (as well as many other websites such as Brainly, Google docs, etc), words underlined in red are spelled incorrectly.

Whether you spelled it incorrectly or did not complete the words, as long as the word is not found in the dictionary, the word would be underlined with a red squiggly line.

~

4 0
3 years ago
To add a glow effect to WordArt text, which of the following should be done?
g100num [7]
Number 2 is the correct answer
8 0
2 years ago
Other questions:
  • Text that has equal left and right margins is said to be
    14·2 answers
  • Given the following sequence of integers: 12, 19, 10, 4, 23, 7, 45, 8, 15 Build a heap by inserting the above set, one integer a
    8·1 answer
  • ______ is/are the replacement of human operation and control of machinery with some form of programmed control.
    11·1 answer
  • A string s is a circular shift of a string t if it matches when the the characters are circularly shifted by any number of posit
    9·1 answer
  • When you are working in Performance Monitor, in the "Add Counters" dialog box, and need more information about a particular coun
    8·1 answer
  • Consider the following code segments that are potential replacements for /* missing code */.
    6·1 answer
  • What two windows security updates do most organizations always patch?
    7·1 answer
  • What is the core function of an enterprise platform
    12·2 answers
  • Jade has to create a workbook for storing information of students participating in the annual state-level sports competition. Th
    5·1 answer
  • 3. Which part of the computer is used<br> for typing?<br> a. Mouse<br> b. Keyboard
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!