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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:07:04+00:00 2026-05-13T07:07:04+00:00

I have a set of objects, and I need to produce a sorted list,

  • 0

I have a set of objects, and I need to produce a sorted list, but my comparison function is incomplete and leaves some room for “imagination” on the part of the sorting algorithm.

Specifically, given a collection of trees like the following:

  A      E
  |      |
  B--C   F
  |
  D

What I have on hand is the set of nodes {A, B, C, D, E, F}, in no particular order, and a function to test direct parent-child relationships:

parent(A, B)
parent(A, C)
parent(B, D)
parent(E, F)

I need to flatten this into a list where parents come before their children, but other than that, the order is unimportant. So any of these results would be acceptable:

A, B, C, D, E, F.

A, B, D, C, E, F.

E, F, A, B, C, D.

A, E, B, C, F, D.

The set will be small, a few dozen at most, so I’m not too concerned about performance. What I am concerned about is avoiding temporary data structures other than lists: due to limitations of the language I’m using, organizing these items into a temporary tree (for example) would be unpleasant.

  • 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-13T07:07:04+00:00Added an answer on May 13, 2026 at 7:07 am

    You could use this simple algorithm:

    while unsorted set is not empty {
        elem = get element from unsorted set
        while elem has parent and parent is in unsorted set {
            elem = parent of elem
        }
        add elem to result list
        remove elem from unsorted set
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of objects I'd like to do some operations on, in
I have a parent-child view model object structure set up and need to update
I have a set of objects that I want to conform to an interface,
I have an odd problem with Django. I have a set of objects that
I have several objects set up in Core Data, one of which is Deck
I have set up a Core Data model where I have two objects, say
Say I have a set myset of custom objects that may be equal although
I have a class that serializes a set of objects (using XML serialization) that
I have an API that filters a set of objects based on the ID
So I have an object which contains a set of objects in a private

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.