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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:11:04+00:00 2026-05-17T00:11:04+00:00

Ok, I ran into this tree question which LOOKED simple, but started driving me

  • 0

Ok, I ran into this tree question which LOOKED simple, but started driving me nuts.

The tree given is LIKE a binary search tree, but with one difference:

  1. For a Node, leftNode.value < value <= rightNode.value. However, (by their omission of any further info, and by their example below) this ONLY applies to the immediate children, not the nodes beneath each child. So it’s possible to have a value somewhere in the left subtree that is >= the current node’s value.

This is NOT a self-balancing tree; the existing tree structure will not be changed on an insert, aside from adding the new value in a new leaf node. No switches or shifts of values or nodes allowed.

Also given was an example of the tree structure after test values were inserted:

If we insert 8, 5, 9, 3, 3, 2, 12, 4, 10:


   8


   8
  5  


   8
  5 9


   8
  5 9
 3


   8
  5 9
 3
  3


   8
  5 9
 3   
2 3


   8
  5 9
 3   12
2 3


   8
  5 9
 3   12
2 3
   4


    8
  5   9
 3  10 12
2 3
   4

I assumed the 10 was the right child of 5, since the given constraint prevents it from being the left child of 9.

My requirements, given the rule above for nodes and the example of expected tree structure and behavior for given input: write a traversal and insertion algorithm for this tree.

Since this isn’t a real BST and we’re not allowed to alter the tree, I couldn’t think of any clever way to perform traversal, other than using another data-structure to get this in order.

I’ve got an insertion algorithm which might work, but since it would have to allow back ups to the parent node and exploration of the other path (in both cases where it starts traveling down the left or the right), it would be a really funky looking algorithm.

This question was placed alongside normal, basic programming questions, so it seemed a little out of place. So…any insights here? Or am I overlooking something obvious?

EDIT: Problem solved. It WAS a typo introduced by the test-giver. This was meant to be a BST, but the “10” in the example was placed in the wrong position; it should have been the left child of “12”.

  • 1 1 Answer
  • 1 View
  • 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-17T00:11:05+00:00Added an answer on May 17, 2026 at 12:11 am

    Te examples makes sense until the 10 appears. Basic assumption: It’s a typo. But it can’t (and doesn’t look to) be a child of 5. It is the left child of 9.

    But it’s also the first that would require restructuring the Tree (to fit it between 9 and 12). To me it looks like the last picture is half-way such a restructuring. Are we seeing the end of the story?

    Edit

    Ok, I didn’t read rule 2 completely. It looks like 10 should have become the left-child of 12. There is no good reason for the Insert to take a left branch at the root.

    If 10 is the child of either 5 or 9, it stops being a BST or anything else but an unordered binary tree.

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

Sidebar

Related Questions

I know this question has been asked before, but I ran into a problem.
This originally was a problem I ran into at work, but is now something
I've actually solved this, but I'm posting it for posterity. I ran into a
I'm trying to use WCF Data Service with Subsonic, but ran into this error
I ran into this today when unit testing a generic dictionary. System.Collections.Generic.Dictionary<int, string> actual,
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Today, I ran into this weird problem with a user using Mac OS X.
This morning I ran into an issue with returning back a text string as
I'm writing a C parser using PLY, and recently ran into a problem. This
Just ran into this: #include <iostream> using namespace std; int main(int argc, char** argv)

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.