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
We write programs as a sequence of operation. they flow through the computer as?
lys-0071 [83]
I belive the correct answer would be binary code because computers see the coding as 00100001 
5 0
4 years ago
What is a shortcut for adding a timeline marker
Ludmilka [50]

Answer:

To add a marker to a clip in the Timeline, do the following:

Set up a keyboard shortcut for Add Clip Marker in Edit > Keyboard Shortcuts (Windows), or Premiere Pro > Keyboard Shortcuts (Mac OS).

Select the clip.

Place the Playhead where you want to place the marker.

Press the keyboard shortcut you created for Add Clip Marker.

Explanation:

hope this helps!

5 0
2 years ago
Read 2 more answers
Pedestrians, cyclists, horse drawn vehicles and wheel chair users are known as ___________
Anton [14]
Hi, the answer you are seeking is A. Vulnerable Road Users.

Take care,
Diana
6 0
3 years ago
Read 2 more answers
This career involves answering questions about computer parts and trouble shooting broken computers? Video game designer, comput
adelina 88 [10]

Computer retail sales associate is my best guess. :)

3 0
3 years ago
Most common level of education for a programmer or software developer
shusha [124]

c/c+ also java would be one

8 0
3 years ago
Other questions:
  • create a 3 to 5 step plan for checking out a post on social media for the next time you encounter something questionable.
    11·2 answers
  • find all breweries that specialize in a particular beer style. A brewer is considered specialized if they produce at least 10 be
    5·1 answer
  • Which of the following are not deducted on a typical pay stub
    12·1 answer
  • A water-sports company specializes in custom-made watercrafts and accessories.Their marketing manager decides to use the broad-m
    12·1 answer
  • Which router feature, when enabled, helps computers on the local network automatically discover and communicate with services pr
    12·1 answer
  • What is the most likely reason that a digital artist would use a program such as Autodesk Maya or Max to create 3-D images for a
    12·1 answer
  • Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow
    6·1 answer
  • Which feature helps an edit-test-bug cycle work faster in the python programming language?
    15·2 answers
  • What underlying concept is edge computing based on?
    13·2 answers
  • There is a group of 10 people who are ordering pizza. If each person gets 2 slices and each pizza has 5 slices, how many pizzas
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!