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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:57:40+00:00 2026-06-06T09:57:40+00:00

I have a list of some arbitrary objects, for the purpose of the example

  • 0

I have a list of some arbitrary objects, for the purpose of the example assume they’re (integer, something-else) pairs, but they may be essentially anything:

[(5, a), (3, c), (2, f), (3, a), (4, c), (1, d), (5, b), (5, d)]

I want to group these objects based on one of their properties so that elements sharing the same value of said property are adjacent in the resulting list. For instance, the above list grouped by the integer values:

[(3, a), (3, c), (1, d), (4, c), (2, f), (5, b), (5, a), (5, d)]

As you see, no kind of order is necessary, nor is the operation required to be stable.


The naïve way would be to sort the list. This has the advantages of being well-known, well-tested and fast enough.

I’m being curious, though: is there an algorithm for this that doesn’t involve sorting, while being competitive in terms of complexity (O(n) time with O(n) space or O(n log n) time with O(1) space)?

  • 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-06T09:57:42+00:00Added an answer on June 6, 2026 at 9:57 am

    Consider the problem of removing non-unique entries from an integer array. This problem can be solved by means of the solution to your problem (in linear time and constant space), so your problem cannot be solved simpler than that.

    Unfortunately, I cannot find a good question with a good answer to this problem, but this one is definitely more general and well-known, I’m sure you’ll prove the best solution for that one.

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

Sidebar

Related Questions

I am trying to output some Java objects as JSON, they have List properties
I have a list of Spam objects: class Spam: def update(self): print('updating spam!') some
I have some code which deals with various std::list objects, and I am currently
I have a list with some lis. <ul> <li id=eup>....</li> <li id=1>a</li> <li id=2>b</li>
I have list of images with some simple mouseenter / mouseleave effect. http://jsfiddle.net/4vTCr/ I
I have a list that has some chapter numbers in string. When I sort
I have a list which contains some items of type string. List<string> lstOriginal; I
I have list of catalog paths and need to filter out some of them.
Say you have a std::list of some class. There are two ways you can
I have some std::list<char> list_type Now I have to supply contents of the list

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.