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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:01:31+00:00 2026-05-21T03:01:31+00:00

Give a Set S , partition the set into k disjoint subsets such that

  • 0

Give a Set S, partition the set into k disjoint subsets such that the difference of their sums is minimal.

say, S = {1,2,3,4,5} and k = 2, so { {3,4}, {1,2,5} } since their sums {7,8} have minimal difference. For S = {1,2,3}, k = 2 it will be {{1,2},{3}} since difference in sum is 0.

The problem is similar to The Partition Problem from The Algorithm Design Manual. Except Steven Skiena discusses a method to solve it without rearrangement.

I was going to try Simulated Annealing. So i wondering, if there was a better method?

Thanks in advance.

  • 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-21T03:01:33+00:00Added an answer on May 21, 2026 at 3:01 am

    The pseudo-polytime algorithm for a knapsack can be used for k=2. The best we can do is sum(S)/2. Run the knapsack algorithm

    for s in S:
        for i in 0 to sum(S):
            if arr[i] then arr[i+s] = true;
    

    then look at sum(S)/2, followed by sum(S)/2 +/- 1, etc.

    For ‘k>=3’ I believe this is NP-complete, like the 3-partition problem.

    The simplest way to do it for k>=3 is just to brute force it, here’s one way, not sure if it’s the fastest or cleanest.

    import copy
    arr = [1,2,3,4]
    
    def t(k,accum,index):
        print accum,k
        if index == len(arr):
            if(k==0):
                return copy.deepcopy(accum);
            else:
                return [];
    
        element = arr[index];
        result = []
    
        for set_i in range(len(accum)):
            if k>0:
                clone_new = copy.deepcopy(accum);
                clone_new[set_i].append([element]);
                result.extend( t(k-1,clone_new,index+1) );
    
            for elem_i in range(len(accum[set_i])):
                clone_new = copy.deepcopy(accum);
                clone_new[set_i][elem_i].append(element)
                result.extend( t(k,clone_new,index+1) );
    
        return result
    
    print t(3,[[]],0);
    

    Simulated annealing might be good, but since the ‘neighbors’ of a particular solution aren’t really clear, a genetic algorithm might be better suited to this. You’d start out by randomly picking a group of subsets and ‘mutate’ by moving numbers between subsets.

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

Sidebar

Related Questions

Can anyone give a concise set of real-world considerations that would drive the choice
How can I give set foreign key value field in Entity Framework. I have
I have a php script set up to generate emails. Currently, they give the
I'm trying to set up a Sybase query that will give me the following
There are a number of widgets that allow pre-set address and give the current
To give an example of the kind of request that I can't figure out
How to give a set of check boxes a same CSS class. Thanks.
Is there any practical difference between a Set and Collection in Java, besides the
I'm looking for a way to compute the range of a give set of
Is it possible to set up SQL Server to give developers read-only access to

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.