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

  • Home
  • SEARCH
  • 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 7943107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:10:23+00:00 2026-06-04T00:10:23+00:00

If i construct a binary search tree adding the following values in order: 10,

  • 0

If i construct a binary search tree adding the following values in order:

 10, 7, 16, 12, 5, 11, 2, 20, 1, 14

I get a tree of height 5. Is there a method (other than trial and error) that I can use to determine an ordering of the integers that would create a tree of height 4?

  • 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-06-04T00:10:24+00:00Added an answer on June 4, 2026 at 12:10 am

    I haven’t thought this through completely, but one way of getting a tree of specific depth is to sort your elements before inserting them: i.e. sorting then inserting N elements into a binary search tree will produce a tree of depth N.

    You might be able to:

    1. Sort your elements
    2. Insert a specific K=4 of them to produce a tree of depth K
    3. Insert the remaining elements in such a way that the tree doesn’t get deeper.

    (Of course, choosing which K elements to start with and a strategy for inserting the remaining elements is the tricky part — but maybe this would be a start?)


    Edit: I think a general solution is possible, assuming K is big enough. How about this:

    1. Given 10, 7, 16, 12, 5, 11, 2, 20, 1, 14
    2. Sort your elements: 1, 2, 5, 7, 10, 11, 12, 14, 16, 20
    3. Insert the last K=4 elements, then the last K-1, then K-2, and so on, down to 1.

    For example, after sorting and inserting the last 4:

    12
      \
       14
         \
          16
            \
             20
    

    …then after inserting the last 3:

      12
     /  \
    7    14
     \     \
      10    16
        \     \
         11    20
    

    …then after the last 2:

        12
       /  \
      7    14
     / \     \
    2   10    16
     \    \     \
      5    11    20
    

    …and finally, after inserting the last element:

          12
         /  \
        7    14
       / \     \
      2   10    16
     / \    \     \
    1   5    11    20
    

    …you’re left with a BST of height K=4.

    Note that this approach will only work when K is big enough — specifically, when K(K+1)/2 >= N.

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

Sidebar

Related Questions

I have rewritten the Binary Search Tree code found in the following links to
Can we prove that one can unambiguously construct a binary tree from its in-order
I am writing a delete member function for a Binary Search Tree. I have
I have been working on a simple binary search tree for a larger project.
I'm trying to construct a binary tree (unbalanced), given its traversals. I'm currently doing
Do you know, please, if C++ STL contains a Binary Search Tree (BST) implementation,
I currently have a binary search tree setup, utilizing templates to allow me to
I know that In-order traversal(VISIT LEFT, VISIT ROOT, VISIT RIGHT) on a binary search
I'm trying to eliminate any memory leaks in in my Binary Search tree that
I've created a binary search tree, each node of my binary tree is setup

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.