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]
3 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]3 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
PL I BEG YOU HELP
Murrr4er [49]

Answer:

Answers in explanation. Try to ask one question at a time, it is easier for people to answer single questions and you will get answers faster.

Explanation:

15. A

16. D

17. B + C

18. A+B+D

19. B+C+D

**20. is NOT Planned personal leave for documentation developers and proof readers. The other 4 answers are correct

21. Presentation notes + Outline

22.B

23.D (im not entirely sure about this one)    

8 0
3 years ago
Charles sends Julia text messages every morning insulting her appearance and threatening to hurt her. He writes unflattering des
aalyn [17]
What is the question?
4 0
3 years ago
Read 2 more answers
There are many potential risks associated with the internet. what do we call the distribution and access of illegal copies of di
GarryVolchara [31]

The potential risks that is linked with the use of internet as a resource point is known to be copyright infringement.

<h3>What is Copyright infringement?</h3>

This is known to be the creation of a book or any other resource material that has been copyrighted and protected without taking the granted permission of the copyright holder who is found to be the author of the work.

Note that The potential risks that is linked with the use of internet  resource point is known to be copyright infringement and one can be punish for it.

Learn more about copyright infringement from

brainly.com/question/14855154

#SPJ4

6 0
2 years ago
Which type of polish grade uses green-colored connectors to help you keep from using the wrong connector type
Anestetic [448]

Answer:

Medium Grade Liquid Metal Polish. pls give me brainliest

8 0
2 years ago
A student is conducting an experiment in which he adds an inhibitor to an enzyme-catalyzed reaction that contains alkaline phosp
Zigmanuir [339]

Answer:

competitive

Explanation:

An inhibitor is a substance that hinders the action of an enzyme. An inhibitor may be competitive or non competitive.

A competitive inhibitor is an inhibitor that is very similar to the substrate hence it binds to the enzyme instead of the substrate. A noncompetitive inhibitor binds to a site that is different from the active site. This site is called an allosteric site.

If we look at the experiment described in the question, the reaction rate decreases upon addition of the inhibitor. This effect is reversed by adding a large quantity of substrate.

The implication of this observation is that the enzyme and the inhibitor compete for the active site on the substrate.

Hence the inhibitor is a competitive inhibitor.

7 0
2 years ago
Other questions:
  • After modifying a numbered list in her presentation, Su notices the numbers and the text are too close to each other. She knows
    9·1 answer
  • (01.03 LC)
    9·1 answer
  • Draw the hierarchy chart and then plan the logic for a program that calculates a person’s body mass index (BMI).
    11·1 answer
  • Yall rachits and yall eat butt xD
    10·2 answers
  • CHALLENGE ACTIVITY 3.7.2: Type casting: Reading and adding values.
    10·1 answer
  • Default tab stops are set in word every _______ inch.<br> a. ¼<br> b. ¾<br> c. ½<br> d. 1
    15·1 answer
  • Precautionary measures to be observed when using ICT tools​
    15·1 answer
  • Write a procedural programming loop.. Your loop should start variable n with a value of 10 and count down to zero. The loop shou
    10·1 answer
  • Why it is not recommended to add sound effect on slide transition? Write at least two reasons.​
    6·1 answer
  • The five types of personal computers are: desktops, laptops, tablets, smartphones, and
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!