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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:16:21+00:00 2026-05-26T07:16:21+00:00

I have to build add the branches (nodes) to a tree view. I’m struggling

  • 0

I have to build add the branches (nodes) to a tree view. I’m struggling to determine what the lowest O(n) technique is.

My data presents as follows:

Id  ParentId    Value

0   null        Bob
1   0           Amy
2   1           Susan
3   1           Matt
4   2           Keith
5   4           Craig
6   4           Derrick

So the tree would look like:

Tree

All I can come up with is an n^2 algorithm which for every entry scans every other entry to see if they belong as a sub node.
I also am removing entries from the array to scan as they are being added. So it’s a little less than n^2 if memory serves (probably not).

Are there any better techniques?

  • 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-26T07:16:22+00:00Added an answer on May 26, 2026 at 7:16 am

    Assuming your language has some sort of list/vector/resizable array type, this is pretty easy.

    Make an empty list for each ID. Iterate over each row, and if ParentId is not null, add the Id to the ParentId’s list.

    You now have the children for each entry in O(n) time.

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

Sidebar

Related Questions

I have used the folllowing steps to add classes to my build path still
i have one application which is build using VB.NET now i required to add
I have build a custom Html Helper extension as follows: public static string DatePicker(this
I have build my data model using JPA and am using Hibernate's EntityManager 3
I have build their solution and it works but I want to add a
I have a build script fragment that looks as follows: foreach(...) ... add_custom_command( OUTPUT
I have been learning Expressions and using the code below to add build up
I got an issue with Globalize3, i have build a module to add translations
I have a build.gradle file. I need to add a code that executes a
I have build a view with following query. SELECT TRUNC(sysdate - (365), 'YYYY') +

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.