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
You have one ip address provided from your isp with a /30 mask. However, you have 300 users that need to access the internet. Wh
creativ13 [48]

Answer:

a. PAT

Explanation:

20.You have one IP address provided from your ISP with a /30 mask. However, you have 300 users that need toaccess the Internet. What technology will you use to implement a solution?a.PATb.VPNc.DNSd.VLANs

4 0
2 years ago
Which of these file types does not share info in a spreadsheet?
charle [14.2K]

Answer:

A file with extension ".exe".

or A system file

3 0
3 years ago
Select the correct answer.
Marianna [84]
The answer is C) Header. If you go in Word and use the header feature, and put a logo there, it appears on all pages.
7 0
3 years ago
HackerCards is a trendy new card game. Each type of HackerCard has a distinct ID number greater than or equal to 1, and the cost
joja [24]

Answer:

I don't know if this is right output is {1,3}

Explanation:

5 0
3 years ago
What data types would you use to represent following data items:
SVETLANKA909090 [29]
1. I have no clue
2. I have no clue
3. I have no clue
6 0
3 years ago
Other questions:
  • The key invention that enabled computers to go into every home and office is
    7·1 answer
  • In Windows Vista, which location contains the Printer link?
    8·2 answers
  • _______________creates new markets separate to the mainstream; markets that are unknowable at the time of the technology's conce
    8·1 answer
  • Which kind of software allows users to draw pictures, shapes, and other graphical images with various on-screen tools such as a
    14·1 answer
  • If you were the IT manager for a large manufacturing company,what issues might you have with the use of opensource software? Wha
    10·1 answer
  • (I made this up teehee) what anime is katski bakugo from
    15·2 answers
  • Illusions in physcology​
    14·1 answer
  • Various gabs in the digital divide​
    8·1 answer
  • Which Operating System is used most often in households?
    6·2 answers
  • What is the duty of WHH? (white hat hackers)<br><br><br>ANY WHH HERE?<br>​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!