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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:39:08+00:00 2026-06-12T13:39:08+00:00

I want an algorithm (no specific language) to find a subset from a set

  • 0

I want an algorithm (no specific language) to find a subset from a set of integers such that their sum is within a certain range.

For example, if I have a group of people, whose weights are as follows.

var people:{
   jane:126,
   julia:112,
   charles:98,
   john:182,
   bob:213,
   edgar: 237,
   jay: 223,
   dan: 191,
   alex: 210,
   david: 196
}

Now, from these people, I’d like to find a subset whose combined weight is between 818-822 pounds (If you’re trying to do the math… don’t bother, these numbers are out of my head, and I don’t even know if there’s a solution with this dataset). The number of people in the group doesn’t matter, just a group from the larger set. And really, any group will do (although random is better in my case).

Note that this is just a quick example… there would actually be hundreds of people, and it would be possible that there would be no combination that would fit into this criteria. Because the actual numbers would be much larger than this, I’m concerned about a n^n problem and running through thousands of iterations, even though I need this to run very quickly.

Maybe I fell asleep during that day in computer science class, but I haven’t been able to come up with anything other than brute force methods.

I’ve tagged this as javascript, simply because that is closest to my actual implementation (and it reads easier). Open to other solutions, as long as they aren’t predicated on some Cthulhu function somewhere.

I know this is a weird question to ask on SO, but any help here would be appreciated.


Ok, I’m stumped. 23 hours to post a bounty for something that I can grok code-wise — my background is certainly not in this realm, and I have a hard time even discerning the notations used to describe the problem, let alone the solutions.

Anybody want to help me out and throw me some sample javascript code that I can modify to the final project? I’ll be adding a 250pt bounty when I can… but if a decent solution comes through I’ll hand it out when the time comes.

  • 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-12T13:39:08+00:00Added an answer on June 12, 2026 at 1:39 pm

    This is similar to 0-1 Knapsack problem or Subset sum problem.

    If weights are not very large integer numbers, a dynamic programming solution should be efficient.


    Here is javascript implementation of dynamic programming algorithm. If you want random groups, just random shuffle the list of people before applying this algorithm.

    var p = {
       jane:126,
       julia:112,
    ...
    };
    
    function subset(people, min, max)
    {
      var subsets = [];
      subsets[0] = '';
    
      for (var person in people)
      {
        for (var s = min-1; s >= 0; --s)
        {
          if (s in subsets)
          {
            var sum = s + people[person];
    
            if (!(sum in subsets))
            {
              subsets[sum] = subsets[s] + ' ' + person;
    
              if (sum >= min && sum <= max)
              {
                return subsets[sum];
              }
            }
          }
        }
      }
    
      return 'Not found';
    }
    
    print(subset(p, 818, 822));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a searching algorithm for sequence of words. For that i
I have this algorithm that I want to implement on VB6. Sub Main() dim
I want to remove some elements from a vector and am using remove_if algorithm
I'm looking to find out if a particular algorithm already exists. I want to
sorry for such a specific question but upon looking at the following algorithm written
My company maintains a domain-specific language that syntactically resembles the Excel formula language. We're
I want an efficient algorithm to fill polygon with an Image, I want to
I want to use encryption algorithm available in .Net Security namespace, however I am
I want to use Levenshtein algorithm to search in a list of strings. I
I want to work on the Rijndael algorithm using C#. Can anybody help me

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.