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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:47:16+00:00 2026-06-18T05:47:16+00:00

Having a Binary Search Tree of int create a linked list of all the

  • 0

Having a Binary Search Tree of int create a linked list of all the integers less than a given integer x value.

What I’ve tried?

1)brutal solution(inefficient)

An inorder visit of the BST, I insert a node in the list for every integer int the Bst,
and then I free every node of the list starting from x

2)more efficient but wrong

I make a search and when I find x, I create a list with an in-order visit of the left son of the node where I’ve found x.

It’s obvious wrong, for example considering the follow BST:

                         10
                        /  \
                       9    11
                      /       \
                     5         15
                    / \        / \
                   1   8      13  19
                             /  \
                            12  14

with this solution if x=15 I just consider {12,13,14}, it would work just for x=root.

The question is How can I do?

  • 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-18T05:47:17+00:00Added an answer on June 18, 2026 at 5:47 am

    If you store the parent node of each node, a more efficient solution can be implemented, as long as you don’t care about the order of the elements in the result list:

    1. Create a new list to save the result
    2. Find the node of interest
    3. Add to the list all the nodes in the left subtree of the node found on step 2, using any traversal you fancy (in-order, pre-order, etc.)
    4. Starting from the parent of the node found on step 2, go up through all the parents adding each node in the way until the current node is either the root node or a node to the left of its parent
    5. Finally, add all the elements to the left of the node found on step 4, again using any traversal
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What exactly is the point of having a key-value pair in a binary search
I'm working on a binary search tree console application, specifically, a method to list
I am having trouble finding the smallest element of a binary search tree. I
I read about binary search trees that if it is a complete tree (all
I'm coding a binary search tree and I'm having a little trouble finding a
I'm having problems converting a binary rooted tree to newick format. The full explanation
Im having a problem with python.. I have a binary tree node type: class
Having a sorted list and some random value, I would like to find in
I've been trying to implement a binary search tree in C++ for fun. My
I'm having trouble interpreting a certain question about inserting elements to a binary search

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.