Questions
Please based on my python code. do the following steps: thank you Develop a method build_bst...

Please based on my python code. do the following steps:

thank you

  1. Develop a method build_bst which takes a list of data (example: [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]) and builds a binary search tree full of Node objects appropriately arranged.
  2. Test your build_bst with different sets of inputs similar to the example provided above. Show 3 different examples.
  3. Choose 1 example data.  Develop a function to remove a node from a bst data structure.  This function should consider all the three cases:  case-1: remove a leaf node, case-2: remove a node with one child and case-3: remove a node with two children. Show an example.

Perform tree balancing after node deletion if necessary.You can choose AVL tree or Red Black tree implementation.

Perform the time complexity for this function.Briefly explain?

  1. Write a function which takes two bst and merges the two trees.  The function should return the merged tree.  Show an example.

Perform tree balancing after merge a tree if necessary.You can choose AVL tree or Red Black tree implementation.

Perform the time complexity for this function.

Here is my python code:

from queue import Queue

class Node:

def __init__(self, data):

self.parent = None

self.left = None

self.right = None

if isinstance(data, list):

self.build_tree(data)

return

self.value = data

def build_tree(self, L):

q = Queue()

q.put(self)

self.value = L[0]

for i in range(1, len(L), 2):

node = q.get()

node.left = Node(L[i])

node.left.parent = node

q.put(node.left)

if i+1 == len(L):

return

node.right = Node(L[i+1])

node.right.parent = node

q.put(node.right)

def min(self):

if self.left is None or self.right is None:

if self.left is not None:

return min(self.value, self.left.min())

if self.right is not None:

return min(self.value, self.right.min())

return self.value

return min(self.value, self.left.min(), self.right.min())

def max(self):

if self.left is None or self.right is None:

if self.left is not None:

return max(self.value, self.left.max())

if self.right is not None:

return max(self.value, self.right.max())

return self.value

return max(self.value, self.left.max(), self.right.max())

def preorder(self):

if self.value is None:

return

print(self.value, end=' ')

if self.left is not None:

self.left.preorder()

if self.right is not None:

self.right.preorder()

if __name__ == "__main__":

#L = [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]

L = [int(x) for x in input().split()]

root = Node(L)

root.preorder()

print()

print(f"Minimum node in tree: {root.min()}")

print(f"Maximum node in tree: {root.max()}")

In: Computer Science

Multiple choice: The presence of a black hole in a galaxy core can be inferred from...

Multiple choice: The presence of a black hole in a galaxy core can be inferred from (a) the total mass of the galaxy; (b) the speeds of stars near the core; (c) the color of the galaxy; (d) the distance of the galaxy from the Milky Way Galaxy; or (e) the diminished brightness of starlight in the galaxy core, relative to surrounding areas.

Multiple choice: Which one of the following statements about black holes is false? (a) Inside a black hole, matter is thought to consist primarily of iron, the endpoint of nuclear fusion in massive stars. (b) Photons escaping from the vicinity of (but not inside) a black hole lose energy, yet still, travel at the speed of light. (c) Near the event horizon of a small black hole (mass = a few solar masses), tidal forces stretch objects apart. (d) A black hole that has reached an equilibrium configuration can be described entirely by its mass, electric charge, and amount of spin (“angular momentum”). (e) A black hole has an “event horizon” from which no light can escape, according to classical (i.e., non-quantum) ideas.

Multiple choice: Which one of the following statements about black holes is true? (a) The surface of the singularity of a black hole is known as the event horizon. (b) Being more massive, a supermassive black hole has a greater gravitational pull than a stellar-mass black hole, so if you approach the event horizon of a supermassive black hole, you will be torn apart more easily than if you approach the event horizon of a stellar-mass black hole. (c) If the Sun were to become a black hole of the same mass, Earth would spiral into the black hole and be eaten. (d) The “photon sphere” is a region inside a black hole where photons orbit the center, so they cannot escape. (e) In principle, energy can be extracted from a region outside a rotating black hole.

Multiple choice: Which one of the following statements about the detection (or potential detection) of black holes is false? (a) Black holes cannot be detected because they emit no light and are therefore impossible to directly observe. (b) A binary pair of black holes was recently detected through measurements of the gravitational waves emitted when they merged to form a single black hole. (c) The presence of supermassive black holes in the centers of galaxies has been inferred from the motions of stars and gas near them. (d) Evidence for black holes can be found if material in the surrounding accretion disk goes through the event horizon and fades from view, rather than releasing energy as it hits a hard stellar surface. (e) Candidate black holes are sometimes found in binary systems that suddenly brighten at X-ray wavelengths.

In: Physics

#include <stdio.h> #include <stdlib.h> // The below function Merges two subarrays of arr[]. // First subarray...

#include <stdio.h>
#include <stdlib.h>
// The below function Merges two subarrays of arr[].
// First subarray is arr[low..mid]--left to middle
// Second subarray is arr[mid+1..high]--middle+1 element to right most element
void merge(int arr[], int low, int mid, int high)
{
int i, j, k;
int len1 = mid - low + 1;
int len2 = high - mid;

//create two temporary arrays
int A[len1], B[len2];

/* Copy data to temporary arrays A[] and B[] */
for (i = 0; i < len1; i++)
A[i] = arr[low + i]; //Copies first half of array
for (j = 0; j < len2; j++)
B[j] = arr[mid + 1 + j]; //Copies second half of array

/* Merge the temporary arrays again into arr[low..high]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = low; // Initial index of merged subarray
while (i < len1 && j < len2) {
if (A[i] <= B[j]) {
arr[k] = A[i];
i++;
}
else {
arr[k] = B[j];
j++;
}
k++;
}

/* The remaining elements of A[] should be copied, if there
are any */
while (i < len1) {
arr[k] = A[i];
i++;
k++;
}

/* The remaining elements of B[] should be copied, if there
are any */
while (j < len2) {
arr[k] = B[j];
j++;
k++;
}
}

/* low is for left most index and high is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int low, int high)
{
if (low < high) {
// checks if the left index is less than right index and avoids overflow for
int mid = low + (high - low) / 2;

// Sort first half from low to mid
mergeSort(arr, low, mid);
//Sort second half from mid+1 to high
mergeSort(arr, mid + 1, high);

merge(arr, low, mid, high); //Call merge function
}
}


/* Function to print the array */
void print(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}

/* main program to call the mergesort functions and read inputs*/
int main()
{
int n; printf("enter number of elements");
scanf_s("%d", &n);
int arr[n];
if (n <= 50 && n >= 0)// condition to check if input less than 50
{
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
printf("Given array is \n");
print(arr, n);
mergeSort(arr, 0, n - 1);

printf("\nSorted array is \n");
print(arr, n);
return 0;
}
else
printf("invalid count entered");//since count should be between 0 and 50
}

why it has an error

I wrote c program in visual studio. but it has error   int A[len1], B[len2];

and

In: Computer Science

A new multinational company seeks to sell its productsin the Kenyan market. Advice them on...

A new multinational company seeks to sell its products in the Kenyan market. Advice them on the main marketing strategies they can employ in segmenting this new found market

In: Finance

Assess the value of warrants, options, hedge instruments, and the methods of pricing a new equity...

Assess the value of warrants, options, hedge instruments, and the methods of pricing a new equity issue describing what key factors are requisite to launch a successful new stock.

In: Finance

Did women really possess significant power in New France? What was life like for women in...

Did women really possess significant power in New France? What was life like for women in New France? Need information in 800 words.
Thank you

In: Operations Management

How does one distinguish the new global terrorism from terrorism that occurred in the 1960s and...

How does one distinguish the new global terrorism from terrorism that occurred in the 1960s and before? What characteristics are new and what attributes have remained the same?

In: Psychology

Assume that the marginal abatement cost curves (MACs) are linear and that the firm currently faces...

Assume that the marginal abatement cost curves (MACs) are linear and that the firm currently faces a standard imposed at the optimal level of pollution. Suppose a new technology can be adopted at zero cost, which causes the MAC to swing downwards. Also, assume that if the firm adopts the technology, the regulator automatically adjusts the standard to its new optimal level. Under what conditions will the firm adopt the new technology?

In: Economics

A company is considering a new way to assemble its golf carts. The present method requires...

A company is considering a new way to assemble its golf carts. The present method requires 42.3 minutes, on the average, to assemble a cart. The mean assembly time for a random sample of 24 carts, using a new method of assembling was 40.6 minutes with a standard deviation of 2.7 minutes. Use a .10 level of significance to determine if there is evidence that the new method if faster. What will be the value of your critical value?  

In: Statistics and Probability

A company is considering a new way to assemble its golf carts. The present method requires...

A company is considering a new way to assemble its golf carts. The present method requires 42.3 minutes, on the average, to assemble a cart. The mean assembly time for a random sample of 24 carts, using a new method of assembling was 40.6 minutes with a standard deviation of 2.7 minutes. Use a .10 level of significance to determine if there is evidence that the new method if faster. What will be the value of your critical value?

In: Statistics and Probability