Question

Suppose you have two binary search trees P and Q. Let P and Q be the number of elements inP and Q, and let hp and ho be the h

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question A.
We traverse tree P and add it's each element into Q one by one. There are |P| elements and adding each of them takes at most hQ times and Q's height could become maximum hQ + |P|, So in worst case we will need |P|(hQ+|P|) operations which is equal to O(|P|2).
Question B.
If smallest element of Q is greater than largest element of P, we can just wind largest element in P and whole tree of Q as it's right child tree and union tree will still be binary search tree. Finding largest element in P takes at most hP operations and adding child node is simple O(1) operation so we get time complexity O(hP).


Comment down for any queries

Please give a thumb up

Add a comment
Know the answer?
Add Answer to:
Suppose you have two binary search trees P and Q. Let P and Q be the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ) True or false: Any two (possibly unbalanced) binary search trees containing n elements each can...

    ) True or false: Any two (possibly unbalanced) binary search trees containing n elements each can be merged into a single balanced binary search tree in O(n) time.

  • Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elem...

    Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elements. In this problem, you will show how to transform Ti into T2 (i.e. Ti is altered to now have the same structure as T2) through a series of rotation operations. (a) Define a binary tree to be a right-going chain if no node in the tree has a left child (in other words, the tree is a linked list formed through...

  • A student believes that Binary Search Trees possess the following property.

     (a) A student believes that Binary Search Trees possess the following property. Suppose we search for a key and the matching node is a leaf node. Let L be the set of all nodes to the left of the search path, P the set of all nodes on the search path, and R be the set of all nodes to the right of the search path. The student claims that any three keys I ∈ L, p ∈ P, and...

  • I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if...

    I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...

  • Suppose a binary search tree has multiple nodes containing the same key value, k. Let node...

    Suppose a binary search tree has multiple nodes containing the same key value, k. Let node p be the lowest common ancestor of such nodes. Then, the key of p must be also k. If this is true, provide an argument. Otherwise, provide a counterexample.

  • just explain it in english would be enough. modify the standard definition of a binary search...

    just explain it in english would be enough. modify the standard definition of a binary search tree to add a field N.size at each Suppose that we node, which records the size of the subtree under N'Tincluding N itself). A. Explain how to modify the procedure for adding both the case where X is not yet in the tree and is added, and the case where X is already in the tree, and the tree remains unchanged. element X to...

  • In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree...

    In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree of height with each node having at most two children with the property that value of a node is at most the value of its children. Such heap containing n elements can be represented (stored) as an array with the property Suppose that you would like to construct a & min Heap: each node has at most& children and the value of a node...

  • Suppose you are given a balanced binary search tree with 15 nodes in it, containing the even numb...

    Suppose you are given a balanced binary search tree with 15 nodes in it, containing the even numbers from 2 to 30 inclusive. (a) (5 points) Draw this tree. (b) (3 points) Explain how you would check if the number 18 is in this tree, and state the number of operations this would take. (c) (2 points) Explain how you would insert the number 27 into this tree, and state the number of operations this should take.

  • I also don't quite understand the meaning of N.size, is N.size (the sum of nodes) (a...

    I also don't quite understand the meaning of N.size, is N.size (the sum of nodes) (a node and its sub trees) has? please also explain that, thank you. modify the standard definition of a binary search tree to add a field N.size at each Suppose that we node, which records the size of the subtree under N'Tincluding N itself). A. Explain how to modify the procedure for adding both the case where X is not yet in the tree and...

  • (20 points) Suppose you are given a binary search tree T of n nodes (as discussed...

    (20 points) Suppose you are given a binary search tree T of n nodes (as discussed in class. each node v has v.left, v.right, and v.key). We assume that no two keys in T are equal. Given a value x, the rank operation rank() is to return the rank of x in T, which is defined to be one plus the number of keys of T smaller than 2. For example, if T has 3 keys smaller than r, then...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT