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
A vast global network that is made up of many smaller interconnected networks is known as:
Galina-37 [17]

The answer is The Internet.   It is a vast global network that is made up of many smaller interconnected networks. It connects to millions of computer units world wide, in which any computer can communicate with any other computer as long as they are both connected to the Internet. It also made access to information and communication easier.

6 0
3 years ago
Read 2 more answers
Get user input as a boolean and store it in the variable tallEnough. Also, get user input as a boolean and store it in the varia
frozen [14]

Answer:

I will code in JAVA.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 

boolean tallEnough;

boolean oldEnough;

Scanner input = new Scanner(System.in);

tallEnough = input.nextBoolean();<em> //wait the input for tallEnough</em>

oldEnough = input.nextBoolean(); <em>//wait the input for OldEnough</em>

   if(tallEnough && oldEnough){

   System.out.print(true);

   } else {

   System.out.print(false);

   }

}

}

Explanation:

First, to accept user inputs you have to import the class Scanner. Then declare both variables before allowing the user to set input values for both boolean variables.

In the if-else statement checks if both variables are true, then prints true. Another case prints always false.

8 0
2 years ago
Which of the following applies to a DNS caching server? (Choose all that apply.)
Alborosie

Answer:

The answers are:  it is used to enable fast DNS queries and  It can help reduce the amount of network traffic generated by DNS servers.

Explanation:

Because a DNS server can resolve a query from tis local data sends a recursive qyery to a root server.

3 0
3 years ago
What is custom software
Kobotan [32]
A custom sofware is a computer program or website written <span>specifically for your company,</span>
4 0
3 years ago
Read 2 more answers
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To ac
Vikentia [17]

Answer:

input-year taken 2020

2020 is divisible by 2

output- 2020 is a leap year

3 0
2 years ago
Other questions:
  • What is a URN (include example)
    13·1 answer
  • GUI allows users to communicate with a device and see what they are doing onscreen.
    9·1 answer
  • How to search for the largest files on my computer vista?
    5·1 answer
  • Help !!!!!
    9·1 answer
  • The words that follow a code number in the cpt manual are called the
    12·1 answer
  • Why security must be planned, tested, and ready by the time the erp implementation is at go-live?
    11·1 answer
  • What is one advantage of hard-disk recording?
    12·1 answer
  • How many binary digits does a single hexadecimal digit represent?
    13·1 answer
  • What is a web browser​
    9·1 answer
  • he primary purpose of a database query is to a. find and retrieve specific information. b. correct information in the database.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!