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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:59:15+00:00 2026-05-11T13:59:15+00:00

I was wondering what would be the fastest way to sort an array of

  • 0

I was wondering what would be the fastest way to sort an array of objects in the same order as a different array.

Here is an example in C#:

class MyClass {     public MyClass(int value)     {         this.value = value;     }     int value;     public int Value     {         get { return value; }         set { this.value = value; }     } }       static List<int> sortedValuesList;     static List<MyClass> objectList; 

What is the fastest way of sorting objectList in the same order as sortedValuesList? There might be multiple objects with the same value.

I already have simple algorithm that can do it, but it’s O(n^2) and requires extra memory.

EDIT: I guess it’s not clear what I’m trying to do. Let’s say a user sees a data grid of salespeople on the screen. He can sort them by any column he wants. Now the user clicks on a button and a table of customers is being shown. Every customer references one of the salespeople. I want to sort the customer list, based on the order of salespeople in previous data grid.

It’s only a theoretical question as I don’t need more performance. I was just wondering if there is some nice sorting algorithm when you need to use a lookup table to compare objects.

  • 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. 2026-05-11T13:59:16+00:00Added an answer on May 11, 2026 at 1:59 pm

    Break it into steps:

    1. Go through your sortedValuesList and build a map from values -> index positions; this is O(n log n)
    2. Go through your objects and add the index in a temporary field (again, O(n log n))
    3. Sort your list by the temporary field (also O(n log n))

    Total algorithm, O(n log n).

    Alternatively, if you don’t want to have the scratch field, you can look up the sort key via the map each time for an overall O(n (log n)^2)

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

Sidebar

Related Questions

I was wondering if InnoDB would be the best way to format the table?
I was wondering what would be the most ethical way to consume some bytes
I was wondering what would be the best way to install the membership schema
I provide a web service to my organisation. i was wondering would anyone recommeding
I was wondering what would be the best strategy to implement a badges system
I'm wondering what would be the best prectice regarding mainataining connections to the database
As a follow-up to another question , I was wondering what would be the
Just wondering how you would go about implementing something similar to stackoverflow'd related questions.
I'm wondering how you would go about designing a good permgen space string in
I was wondering if it would be possible to retrieve the complete list of

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.