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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:40:16+00:00 2026-05-20T06:40:16+00:00

I have a list of integers, for example 1,2,2,3,4,1 . I need to be

  • 0

I have a list of integers, for example 1,2,2,3,4,1. I need to be able to check for equivalence (==) between different lists.

However, I do not mean a simple number wise comparison. Each of these lists actually denotes a set partition, where the position in the list denotes the index of an element and the number denotes an index of the group. For example in the former, element 0 and element 5 are in the same group, element 1 and 2 are in the same group and element 3 and 4 are both in their own individual groups. The actual index of the group is not important, only the grouping.

I need to be able to test equivalence in this sense, so for example the previous list would be equivalent to 5,3,3,2,9,5, since they have the same grouping.

The way I have been doing this is reducing the array to a kind of normal form. I find all numbers having the same value as the first number, and set these all to 0.
I then continue in the list until I find a new number, find all numbers of the same value is this and set them all to 1. I continue in this manner.

In my example, both numbers would reduce to would reduce down to 0,1,1,2,3,0 and of course I can then just use a simple comparison to see if they are equivalent.

However this is quite slow, as I have to make several linear passes over the list. So to cut to the chase, is there any more efficient manner of reducing these numbers to this normal form?

Howver, more generally, can I avoid this reduction all together and compare arrays in a different and perhaps more efficient manner?

Implementation details

  • These arrays are actually implemented
    as bitsets to save space, so I really do have to iterate over the whole list every time as there is no rb_tree esque hashing going on.
  • Large
    numbers of these arrays will be
    stored in an stl unordered_set, hence
    the requirement for a hash should be taken into consideration
  • 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-20T06:40:17+00:00Added an answer on May 20, 2026 at 6:40 am

    Try iterating through the two sequences in parallel, keeping a map (either std::map or an array) from values in the first array to values in the second and vice versa. If you get to a pair that is not in your table, add it, unless there is something in the table for either that first or second number (since that would indicate inequality). For example:

    1,2,2,3,4,1
    5,3,3,2,9,5
    

    You would add 1->5, 2->3, 3->2, and 4->9 and the comparison would pass. For something slightly different:

    5,3,3,2,9,5
    1,2,2,3,2,1
    

    you would add 5->1, 3->2, 2->3, then 9->2 would fail since there is already a binding for 2 in the second sequence; thus, you would know that the sequences were not equivalent.

    For creating a hash function, you would probably need to do the normalization that you are doing, but it should require only one pass through the sequence. Again, keep maps in both directions, but if you find an unknown element in the input sequence, map it to the next available number, and otherwise use the map to transform the input sequence into a normalized one.

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

Sidebar

Related Questions

I have a list of integers or of strings and need to pass it
I have a list of integers which I need to parse into a string
I have a list of elements (integers) and what I need to do is
I have a list of integers like 1, 2, 3, 4, 5, 6, 7,
Say I have a list of integers: List<int> myInts = new List<int>() {1,2,3,5,8,13,21}; I
Say we have a list of integers from 0 to 1000: [0, 1, 2,
We have a pojo that needs to have a list of integers. As an
I have a list of numbers ( integers ) (say, from 1 to 10).
I have a list containing a tuples and long integers the list looks like
So I have a big list of integers I have to work with (in

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.