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
Programs which tell the computer what to do:<br> a. Software<br> b. ROM<br> c. RAM<br> d. Hard disk
labwork [276]
The answer is A. Software
4 0
3 years ago
Read 2 more answers
Linela Insurance needs to hire twenty accountants immediately to support its accounts receivable process. The hiring and trainin
sukhopar [10]

Answer:

Outsourcing

Explanation:

Outsourcing is a business practice to use third party companies outside business to complete task which were previously done by in-house teams.

Outsourcing is a good cost cutting technique while not compromising very much on the services provided by the business.

There are many pros and cons associated with this technique

Following are some pros

  1. Outsourcing some work increase the efficiency of in house team as they have less work load and they can better focus on their work
  2. Outsourcing work significantly cuts the cost with access to more skilled expertise.
  3. Outsourcing let's you better risk manage. As risk management is shared between both the companies.

Following are some cons

  1. Biggest con of outsourcing is loss of control.When you give your product to a third company to do it for you, you loss control of the product.
  2. With less involvement of the owning business innovation process may see slow growth in out sourced projects
3 0
4 years ago
NEED ASAP!!
kow [346]

Answer:

because he needs to connect them all to the sane network (i think)

4 0
3 years ago
Is a system software that manages the hardware resources and provides services 5o the application software
Alborosie

Answer:

"Operating system" is the right response.

Explanation:

  • The key program collection on something like a computer device that maintains it interacts mostly with underlying hardware of that system is considered as an Operating system.
  • Even without the need for an OS, every consumer isn't able to access either equipment, monitor as well as portable phone or devices.
8 0
3 years ago
What is a BINARY, bits and bytes ​
Stels [109]
A bit (short for binary digit) is the smallest unit of data in a computer. A bit has a single binary value, either 0 or 1. ... Half a byte (four bits) is called a nibble. In some systems, the term octet is used for an eight-bit unit instead of byte.
4 0
4 years ago
Other questions:
  • What does Tristan need to do to add a row at the
    14·1 answer
  • We wish to design a decoder, with three inputs, x, y, z, and eight active high outputs, labeled 0, 1, 2, 3, 4, 5, 6, 7. There is
    5·1 answer
  • DOUBLE POINTS!! PLEASE HELP QUICKLY!!!!!
    15·2 answers
  • Write code that prompts for three integers, averages them, and prints the average. Make your code robust against invalid input;
    7·1 answer
  • QUESTION 4 PRACTICAL EXERSIZE
    7·1 answer
  • Which are the correct commands to create and run an ReactJS project?
    10·1 answer
  • What is the 6 example of computer hardware and explain​
    6·1 answer
  • Can’t be opened because apple cannot check it for malicious software.
    15·1 answer
  • What is one way object-oriented programming differs from procedural programming?
    15·1 answer
  • at the command prompt, type ls -l myscript and press enter. what permissions does the myscript file have? next, type bash myscri
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!