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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:35+00:00 2026-06-04T04:12:35+00:00

I have a very large data set that I’m trying to find the smallest

  • 0

I have a very large data set that I’m trying to find the smallest set that will satisfy all the data sets. The final set must have one value in it that is in all of the data sets

A small sample of the data looks like

[0] => Array
    (
        [0] => 21
        [1] => 21
        [2] => 21
    )

[1] => Array
    (
        [0] => 29
    )

[2] => Array
    (
        [0] => 27
    )

[3] => Array
    (
        [0] => 21
        [1] => 21
        [2] => 21
        [3] => 39
        [4] => 39
        [5] => 43
    )

[4] => Array
    (
        [0] => 29
        [1] => 33
        [2] => 33
        [3] => 43
    )

In this case I need logic to return 21, 27 and 29
The values returned needs to be be the minium number of values that match all arrays. Since I’m a PHP programmer, I writing this function in PHP.

  • 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-04T04:12:36+00:00Added an answer on June 4, 2026 at 4:12 am

    You could follow this algorithm:

    Updated after testing

    $data=array(
                array(21,29,27,57,22),
                array(22,21,23,24,25,26),
                array(31)
                );
    
    $map = array(); // keep a map of values and how many times they occur in other sets
    foreach ($data as $setid => $set) {
        foreach (array_unique($set) as $v) {
            $map[$v][$setid] = true;
        }
    }
    
    function reverseCount(array $a, array $b)
    {
        return count($b) - count($a);
    }
    
    // sort reversed on intersection count
    uasort($map, 'reverseCount');
    
    // after sorting the first number will be the one that occurs the most
    // keep track of which sets have been hit
    $setmap = array(); $n = count($data);
    foreach ($map as $v => $sets) {
        $hits = 0;
        foreach ($sets as $setid => $dummy) {
            if (!isset($setmap[$setid])) {
                --$n;
                ++$hits;
                $setmap[$setid] = true;
            } else {
                continue;
            }
        }
        if ($hits) {
            echo "value $v\n";
            if (!$n) {
                // all sets are hit
                break;
            }
        }
    }
    

    Tested this time. It’s not proven to always get the right result, because this is considered a greedy approximation algorithm.

    But I hope it gives an idea of what you could do. Let me know if anything confuses you or if I’m dead wrong about it 🙂

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

Sidebar

Related Questions

I have a very large possible data set that I am trying to visualize
I have a relatively large set of data that lends itself very naturally to
I have a query that returns a very large data set. I cannot copy
I have a very large data set that I'd like to craft into a
I have a webpage that displays a very large list of data. Since this
I have a very large set of permissions in my application that I represent
I have a very large set of data (~3 million records) which needs to
I have a large data set that I want to clean up for the
I've got a very large xml data set that is structured like the following:
I have been playing at work with some very very large sets of data,

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.