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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:28:14+00:00 2026-05-19T01:28:14+00:00

I have an 1D array containing a set of rankings. e.g. 0|0 1|2 2|2

  • 0

I have an 1D array containing a set of rankings. e.g.

0|0
1|2
2|2
3|1
4|0
5|1

(the first column shown here is the array index)

which i’d like to rank like so

1|2
2|2
3|1
5|1
0|0
4|0

Notice that the indexes stay in numerically ascending order when there is a tie. What sort of algorithm should I be looking at to do this?

  • 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-19T01:28:15+00:00Added an answer on May 19, 2026 at 1:28 am

    As other posters have answered, you probably want a stable sort. Stable sorting algorithms include

    • Insertion Sort
    • Merge Sort
    • Bubble Sort

    If I was to choose, I would probably go with merge sort because it has the best complexity. Insertion sort can beat it on small lists though. I remember reading that there’s one case where Bubble Sort isn’t terrible but I forget what it is.

    However, it’s worth noting that worrying about stability will rule out an algorithm like quicksort which may be the algorithm that your unspecified language uses in its sorting functions.

    Whatever language you’re using, its sort implementation should be able to take a function that will compare two items and establish which one is “greater”. So all you really need to do is write a function which

    • If the ranks are equal, claims that the items with the greater numerical indice is “greater”
    • If the ranks are not equal, claims that the item with the greater rank is “greater”.
    • If both rank and numerical index are are equal, claims that they are equal.

    This is just sorting the items ‘lexicographically’ using whatever sort algorithm comes with the language and removes the need for stability assuming that you can consider two items to be equal if they have the same index.

    The precise protocol that this function follows will vary from language to language.

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

Sidebar

Related Questions

I have a 1d array containing Nd data, I would like to effectively traverse
I have create an array containing person firstname,lastname and number which i populate in
I have a function that generates an array containing menu items: Item 1 SubItem
I have this iPhone app that has an array containing around 50 to 100
I have a REST web service that returns a structure containing an array of
I have a array containing japanese caracters as well as normal. How do I
I have an array containing a list of files. I want to sort it
I have an array containing specific times and I want when the current time
Ruby 1.8.6 I have an array containing numerical values. I want to reduce it
I have an int array containing gray scale values from 0-254, i also have

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.