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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:15:41+00:00 2026-05-27T22:15:41+00:00

I have a perfectly square 64×64 2D array of integers that will never have

  • 0

I have a perfectly square 64×64 2D array of integers that will never have a value greater than 64. I was wondering if there is a really fast way to compare all of the elements with each other and display the ones that are the same, in a unique way.

At the current moment I have this

2D int array named array
loop from i = 0 to 64
    loop from j = 0 to 64
        loop from k = (j+1) to 64
            loop from z = 0 to 64
                if(array[i][j] == array[k][z])
                    print "element [i][j] is same as [k][z]

As you see having 4 nested loops is quite a stupid thing that I would like not to use. Language does not matter at all whatsoever, I am just simply curious to see what kind of cool solutions it is possible to use. Since value inside any integer will not be greater than 64, I guess you can only use 6 bits and transform array into something fancier. And that therefore would require less memory and would allow for some really fancy bitwise operations. Alas I am not quite knowledgeable enough to think in that format, and therefore would like to see what you guys can come up with.

Thanks to anyone in advance for a really unique solution.

  • 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-27T22:15:42+00:00Added an answer on May 27, 2026 at 10:15 pm

    There’s no need to sort the array via an O(m log m) algorithm; you can use an O(m) bucket sort. (Letting m = n*n = 64*64).

    An easy O(m) method using lists is to set up an array H of n+1 integers, initialized to -1; also allocate an array L of m integers each, to use as list elements. For the i‘th array element, with value A[i], set k=A[i] and L[i]=H[k] and H[k]=i. When that’s done, each H[k] is the head of a list of entries with equal values in them. For 2D arrays, treat array element A[i,j] as A[i+n*(j-1)].

    Here’s a python example using python lists, with n=7 for ease of viewing results:

    import random
    n = 7
    m = n*n
    a=[random.randint(1,n) for i in range(m)]
    h=[[] for i in range(n+1)]
    for i in range(m):
        k = a[i]
        h[k].append(i)
    for i in range(1,n+1):
        print 'With value %2d:  %s' %(i, h[i])
    

    Its output looks like:

    With value  1:  [1, 19, 24, 28, 44, 45]
    With value  2:  [3, 6, 8, 16, 27, 29, 30, 34, 42]
    With value  3:  [12, 17, 21, 23, 32, 41, 47]
    With value  4:  [9, 15, 36]
    With value  5:  [0, 4, 7, 10, 14, 18, 26, 33, 38]
    With value  6:  [5, 11, 20, 22, 35, 37, 39, 43, 46, 48]
    With value  7:  [2, 13, 25, 31, 40]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that perfectly works on iPhone os 2.2.1 but when I
I have a Java EE webapp that works perfectly when I run it on
I have this code so far which perfectly but relies on there being a
I have a problem with CSS on Firefox. A fieldset that renders perfectly on
I followed this guide here perfectly and have gone through it again but when
I have a (from what I can tell) perfectly working Linux setup (Ubuntu 8.04)
I have a set of changes which work perfectly against a certain linux version,
I have a wxPython which works perfectly on window xp theme but on switching
I have the following code which works perfectly, but I want to allow access
I have some code here which works perfectly in firefox but not in chrome

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.