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

  • Home
  • SEARCH
  • 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

I have a set of checkboxes that an Admin can tick to give users
Does Flot have an option that can be set to give the chart a
I have a certain set of assertions that I give to z3 which are
How can I give set foreign key value field in Entity Framework. I have
Is there a set of functions that give you the file and/or the folder
I have a fairly complex set of rewrite rules to give my site pages
I have a set of different interfaces and I need to give them access
Suppose I have a database like this: This is set up to give role-wise
I had set breakpoint in source code but it will give me warning that
I have a set of divs with the same class. I need to give

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.