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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:42:14+00:00 2026-06-02T21:42:14+00:00

I have a set of items that are supposed to for a balanced binary

  • 0

I have a set of items that are supposed to for a balanced binary tree. Each item is of the form (data,parent), data being the useful information and parent being the index of the parent node in the binary tree.

Nodes in the tree are numbered left-to-right, row-by-row, like this:

           1
       ___/ \___
      /         \
     2           3
   _/\_        _/\_
  4    5      6    7

These elements come stored in a linked list. How should I order this list such that it’s easier for me to build the tree? Each parent node will be referenced (by index) by exactly two child nodes; if I sort these by parent index, the sorting must be stable.

  • 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-02T21:42:16+00:00Added an answer on June 2, 2026 at 9:42 pm

    You can sort the list in any stable sort, according to the parent field, in increasing order.

    The result will be a list like that:

    [(d_1,nil), (d_2,1), (d_3,1) , (d_4,2), (d_5,2), ...(d_i,x), (d_i+1,x) ]
         ^ 
       the root has no parent...
    

    Note that in this list, since we used a stable sort – for each two pairs (d_i,x), (d_i+1,x) in the sorted list, d_i is the left leaf!

    Now, you can populate the tree in breadth-first traversal,

    Since it is homework – I still want you to make sure you understand everything by your own. So I do not want to “feed answer”. If you have any specific question, please comment – and I will try to edit and explain the relevant parts with more details.

    Bonus: The result of this organization is very common way to implement a binary heap structure, which is a complete binary tree, but for performance, we usually store it as an array, which is very similar to the output generated by this approach.

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

Sidebar

Related Questions

I have a data set of item difficulties that correspond to items on a
I have set up a Core Data model that includes an entity, Item with
I have a set of items. Each item in the set can be related
I have an installer that is supposed to set up a menu item in
I have a set of items that can be in various states. I want
I hope the title makes sense. I have a set of items that I
I have a set of list items in unordered lists that I bind the
I have a Stackpanel and want that the items automatically set their sizes regarding
I have a set of data that is structured like this: ItemA.GroupA ItemB.GroupA ItemC.GroupB
i created a carousel in jquery that slides an item or set of items

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.