Question

In: Computer Science

Part E (3 marks):  What is the shape of a BST that is O(n) to delete the...

Part E (3 marks):  What is the shape of a BST that is O(n) to delete the root?  Draw an example with at least 8 nodes.

Solutions

Expert Solution

For Deleting Root node we have 3 cases

1)Node to be deleted has only right child: Copy the right child to the node and delete the child.

2)Node to be deleted has only left child: Copy the left child to the node and delete the child.

3) Node to be deleted has two children: Find inorder successor of the node. Copy contents of the inorder successor to the node and delete the inorder successor. Inorder predecessor can also use.

For getting O(n) time we need take 3 rd case.

In this example iam explaining Inorder succesor removal which is taking O(n) time.

If you are considering Inorder predecessor just make left child of root have more chldren in the right.

Another way is consider both inorder successor and inorder predecessor and take the best one, but there also we need to traverse entire tree.Time Complexity is always depend on how you are coding.

Here in this image iam using inorder succesor. If you want inorder predecessor and both please leave a comment below.


Related Solutions

Question 3.3                              (Total: 45 marks; part 1: 24 marks; part 2: 15 marks; part 3:...
Question 3.3                              (Total: 45 marks; part 1: 24 marks; part 2: 15 marks; part 3: 6 marks) Star Finder Inc. has provided the following information for the year ended December 31, 2021: Sales revenue $1,300,000 Loss on inventory due to decline in net realizable value $80,000 Unrealized gain on FV-OCI equity investments 42,000 Loss on disposal of equipment 35,000 Interest income 7,000 Depreciation expense related to buildings omitted by mistake in 2020 55,000 Cost of goods sold 780,000 Retained...
Question 3 (12 marks) Part A ( 3 marks) A project (by a competitor) is way...
Question 3 Part A ( 3 marks) A project (by a competitor) is way behind development by five months. Your company's Project Manager Ellie suggested using the "exploit" strategy to supply to the customer. Explain to your team briefly what is this type of risk? Part B ( 9 marks) With reference to the strategy of exploitation above, now create a detailed plan on what you would execute with your team. [Assumption: Budget is not a problem.]
Question 3.3 (Total: 45 marks; part 1: 24 marks; part 2: 15 marks; part 3: 6...
Question 3.3 (Total: 45 marks; part 1: 24 marks; part 2: 15 marks; part 3: 6 marks) Star Finder Inc. has provided the following information for the year ended December 31, 2021: Sales revenue $1,300,000 Loss on inventory due to decline in net realizable value $80,000 Unrealized gain on FV-OCI equity investments 42,000 Loss on disposal of equipment 35,000 Interest income 7,000 Depreciation expense related to buildings omitted by mistake in 2020 55,000 Cost of goods sold 780,000 Retained earnings...
Prove the upper and lower bound of T(n) = T(n/3) + T(2n/3) + O(n)
Prove the upper and lower bound of T(n) = T(n/3) + T(2n/3) + O(n)
In python, Part 1: Estimate the value of e. e is defined as  as n goes to...
In python, Part 1: Estimate the value of e. e is defined as  as n goes to infinity. So the larger the value of n, the closer you should get to e. math.e is defined as 2.718281828459045 You'll write a program that uses a while loop to estimate e to within some defined error range, while having a limit on how many iterations it will attempt. Part 2: Palindrome detection A palindrome is a string that is the same forwards and...
Show for the following recurrence that T(n) = T(n/3) + n*log(n) is O(n*log(n)) (not using the...
Show for the following recurrence that T(n) = T(n/3) + n*log(n) is O(n*log(n)) (not using the Master theorem please)
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN)...
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN) B. Evaluate the following postfix expression. 2 3 4 + * C. In an array representation of heap, what are the parent node of a node a[10]? a[9] a[11] a[5] a[20] There is no easy way to access parent node in such representation. D. In an array representation of heap, what are the children nodes (if any) of a node a[10]? a[11] and a[12]...
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n...
What are Big-O expressions for the following runtine functions?      a) T(n)= nlog n + n log (n2 )        b) T(n)= (nnn)2           c) T(n)= n1/3 + n1/4 + log n      d) T(n)= 23n + 32n      e) T(n)= n! + 2n Write algorithm and program : Find the sum of the integers from 1 through n.     a)Use iterative algorithm and program         b) Use recursive algorithm and program. Order the following functions by growth rate:...
Use Java for the following; Part 1 n!= n * (n –1)* (n–2)* ...* 3 *...
Use Java for the following; Part 1 n!= n * (n –1)* (n–2)* ...* 3 * 2 * 1 For example, 5! = 5 * 4 * 3 * 2 * 1 = 120 Write a function called factorial that takes as input an integer. Your function should verify that the input is positive (i.e. it is greater than 0). Then, it should compute the value of the factorial using a for loop and return the value. In main, display...
Part A Calculate [ H 3 O + ] and pH of the following polyprotic acid...
Part A Calculate [ H 3 O + ] and pH of the following polyprotic acid solution: 0.120 M H 2 CO 3 . Part B Calculate [H3O+] and pH of the following polyprotic acid solution: 0.125 M H3C6H5O7 .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT