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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:03:21+00:00 2026-05-23T14:03:21+00:00

By identical I mean two Arrays contain same elements, order of elements in Arrays

  • 0

By identical I mean two Arrays contain same elements, order of elements in Arrays are not matter here.

The solution I came up with is like this(which turns out a wrong approach as pointed out in comments):

 if the size of two Arrays are equal
 See True, find all elements of Array A in Array B
 All Found,  find all elements of Array B in Array A
 All Found, then I get conclusion two Arrays are identical

However, is there better algorithm in term of time complexity?

  • 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-23T14:03:21+00:00Added an answer on May 23, 2026 at 2:03 pm

    Let’s say you have an User[] array 1 and User[] array 2. You can lop through array one and add them to Dictionary<User, int> dictionary where the key is the user and the value is a count. Then you loop through the second array and for each user in array 2 decrement the count in the dictionary (if count is greater than 1) or remove the element (if count is 1). If the user isn’t in the dictionary, then you can stop, the arrays don’t match.

    If you get to the end and had previously checked length of the arrays is same, then the arrays match. If you hadn’t checked length earlier (which of course you still should have), then you can just verify the dictionary is now empty after completely looping through array 2.

    I don’t know exactly what the performance of this is, but it will be faster than sorting both lists and looping through them comparing element by element. Takes more memory though, but if the arrays are not super large then memory usage shouldn’t be an issue.

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

Sidebar

Related Questions

I have two identical byte arrays in the following segment of code: /// <summary>
Will encrypting two identical plaintext messages with AES in CBC with the same IV
So, I realize that const T& and T const& are identical and both mean
I have two identical tables and need to copy rows from table to another.
I have several identical elements with different attributes that I'm accessing with SimpleXML: <data>
We have 3 identical HP DL380 G5 server here, one of them is running
Given two identical boost::variant instances a and b , the expression ( a ==
I have two almost identical Beans. Bean Item contains a unique identifier (primary key),
I have two large identical-sized files. One is ASCII plain text, and the other
how to find cartesian product of identical arrays? (handshake problem). I found cart_prod() and

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.