Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:38:06+00:00 2026-05-31T07:38:06+00:00

I am not asking how to merge two binary search trees, as this question

  • 0

I am not asking how to merge two binary search trees, as this question did How to merge two BST's efficiently?

I am really asking how to concatenate two trees. So if tree A’s all nodes are smaller than any node of tree B, we can concatenate two trees. But how do I do it efficiently?

My idea is to find tree B’s minimum, and then let tree A be the left child of minimum(tree B).

This is simple enough and the time is O(height of B).

But I guess this solution has some problems:

  1. it may cause the final big tree not balanced any more
  2. What if the worst case running time is O(h), where h is the max height of the two tree?

Actually, The book “Algorithm Design Manual” has this excise. Is my simple solution enough for this exercise?

A concatenate operation takes two sets S1 and S2, where every key in S1 is smaller than any key in S2, and merges them together. Give an algorithm to concatenate two binary search trees into one binary search tree. The worst-case running time should be O(h), where h is the maximal height of the two trees.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:38:08+00:00Added an answer on May 31, 2026 at 7:38 am

    Let A be the smaller set. Assume x = maximum_element(A) and y = minimum_element(B).

    We know x < y. take a node with key value equal to z = (x+y)/2 and make A its left subtree and B its right subtree. remove the added node(with key z) from this BST.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

apologies for not asking a strictly programming question, but this will move on to
In this question I'm not asking how to do it but HOW IS IT
I noticed some confusion initially with my question. I'm not asking about how to
I'm wondering about the feasability of this below. Of course, I'm not asking for
I'm not sure I'm asking the right question here, but I'm looking to provide
I'm very new to xml so I hope I'm not asking any silly question
This is not asking how to convert an arbitrary string to datetime in MSSQL
I'm not asking how to do this, it's more in line of What would
I hope I am not asking a too obvious question here. For my current
I'm not asking as to how go about doing this, but just curious if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.