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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:08:59+00:00 2026-06-01T06:08:59+00:00

I am trying to figure out how to sort a multidimensional data (5 dimensions)

  • 0

I am trying to figure out how to sort a multidimensional data (5 dimensions) in C. I know that using a 5d array is a solution that, from
reading others posts on SO about this topic many folks find, if not altogether unethical, so aesthetically repugnant so as to provoke unceasing projectile vomiting…so I apologize in advance.

Essentially I have an incoming set of data to which I must apply a series of discrete algorithms. Each algorithm has a set of variables, and I need to calculate a ranking of the efficiency of each algorithm with every permutation of the
variables possible.
Ultimately, I need a list sorted by the best-to-worst performing algorithm. The whole
calculation is dynamic, so what works best on one incoming piece of data is unlikely to be the best performer on another…so I can’t eliminate any of the variables because they are poor performers.

Here is how the data looks:

dataValue[ algo ][ lengthVar ][ durationVar ][ plasticityVar ] [ fungibilityVar]

There are:

  • 35 algorithms
  • 10 length variables
  • 230 duration vars
  • 27 plasticity vars
  • 400 fungibility vars

In addition to sorting by algorithm, I would like to have the flexibility to sort on any of the 5 dimensions.

This will be run on a 12 physical/ 24 logical core machine with 192 gig (not meg) of RAM, using VS 2010 C (not C++).

I am assuming that qsort would be the most efficient sorting option. I have searched Google and SO extensively for how to do this to no avail. There are answers for 1d arrays, multidimensional arrays in PHP or C#, etc, but not for C…or at least I can’t find one.

  • 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-01T06:09:00+00:00Added an answer on June 1, 2026 at 6:09 am

    qsort in cstdlib would work. The array is Datatype ***data.

    So first off, lets say that you want to sort the first index of the array. You’d have to write a comparator function to compare two Datatype****s. The comparator should return a value less than zero if ab.

    int myComparator(void *a, void *b){
        Datatype ****c=(Datatype****)a; Datatype ****d=(Datatype****)b
        return algorithmRatingFunction(b)-algorithmRatingFunction(a);
    }
    

    This is pretty obviously inefficient because you have to reevaluate the algorithm for each dataset each comparison, but lets get to that in a sec. After you have the comparator, you can sort the array:

    qsort(data,35,sizeOf(Datatype),myComparator);
    

    That’s it!

    Then there’s the issue of inefficiency… If algorithmRatingFunction takes a long time to complete (which I’m guessing it does), then you’d want to calculate all 35 algorithms once and only once. What you could do is calculate the scores beforehand:

    int scores[35];
    for(int n=0;n<35;n++)
        scores[n]=algorithmRatingFunction(data[n]);
    

    Then create another ordered integer array:

    int ordering[35];
    for(int n=0;n<35;n++)
        ordering[n]=n;
    

    So the state of “ordering” corresponds to the order of your data set. Then, you can create a new comparator:

    int myFasterComparator(void *a, void *b){
        int c=*(int*)a; int d=*(int*)b
        return scores[c]-scores[d];
    }
    

    And call it on ordering:

    qsort(ordering,35,sizeOf(int),myFasterComparator);
    

    Then reconstruct the array using ordering. like so:

    Datatype ****ordereddata[35];
    for(int n=0;n<35;n++)
        ordereddata[n]=data[ordering[n]];
    

    The same holds true for all other levels. Like dasblinkenlight posted, qsort reduces the problem of sorting 5d arrays to that of comparing two 4d arrays. So instead of sorting each 4d array you just have to compare two 3d arrays, etc.

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

Sidebar

Related Questions

I'm trying to figure out how to sort a 2d array into a 3d
I'm trying to figure out how to sort an array by the value of
I'm trying to figure out the correct function in PHP to sort a multidimensional
I'm trying to figure out the best way to sort an array under multiple
I am trying to figure out how to sort the XML list of employees
Trying to figure out how to write a jquery formula that will sum all
Possible Duplicate: Sort multidimensional array by multiple keys I am trying to find some
I'm trying to figure out what this sort of thing is called, and eventually
I'm trying to figure out if the KVC mechanisms provide any sort of help
I'm designing a database and I'm stuck trying to figure out what sort 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.