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 6214821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:56:41+00:00 2026-05-24T06:56:41+00:00

On binary search tree,If I give input as 2,1,3,4,5 the tree will be like

  • 0

On binary search tree,If I give input as “2,1,3,4,5” the tree will be like

              2
              /\
              1 3
                 \
                  4
                   \
                    5

But with input like “5,2,1,3,7,6,8”.

                      5
                     / \
                     2  7         
                    /\  /\
                    1 3 6 8

So my question , how to produce inputs so that above like balanced tree structure is obtained. (I don’t want to use AVL trees) .Do we have tricks to sort or re-arrange numbers in proper way and produce them as input.I’m looking for inputs so that tree can can created height upto 10.

  • 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-24T06:56:42+00:00Added an answer on May 24, 2026 at 6:56 am

    One very simple way to guarantee a balanced tree is to sort the input, then recursively insert the values as follows:

    1. Insert the middle of the whole array.
    2. Recursively insert the left and right halves of the array using this procedure.

    For example, in your case of the values 1 – 8 with 5 removed, you would sort the value as

    1 2 3 5 6 7 8
    

    You would then insert 5, then recursively apply this procedure to the two halves. On the half 1 2 3, you would insert 2, then recursively insert 1 and 3. This gives the ordering so far as

     5 2 1 3
    

    Now, you recursively process the other half, 6 7 8, which inserts 7 and then recursively inserts 6 and 8. Overall, this produces the ordering

    5 2 1 3 7 6 8
    

    which is precisely the ordering you came up with earlier in your post.

    This procedure runs in O(n lg n) time. I’m not positive that this is optimal, so if someone else wants to post a better answer I’d love to see it.

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

Sidebar

Related Questions

I've been trying to implement a delete function for a Binary Search Tree but
I have a PHP script that builds a binary search tree over a rather
Is there a method to build a balanced binary search tree? Example: 1 2
I'm using a library that manipulates a binary search tree. In this library is
Assuming a binary search tree, I would like to return an error in case
I know that SortedDictionary is a binary search tree (and it can almost do
Given a binary search tree and an integer K, i would like to find
I want to create binary search tree data structure in C/C++ where each node
In Scheme, I can use define-struct to make a binary search tree, but how
I want to store some values in a balanced binary search tree using C#.

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.