From b1caf8c6aea2bab16ce0117b8941b64b6834dde8 Mon Sep 17 00:00:00 2001 From: Swati Prajapati <42577922+swatiprajapati08@users.noreply.github.com> Date: Mon, 1 Jun 2020 23:41:32 +0530 Subject: [PATCH 1/2] Minimum sum partition Given an array, the task is to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum. --- DynamicProgramming/Minimum sum partition | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 DynamicProgramming/Minimum sum partition diff --git a/DynamicProgramming/Minimum sum partition b/DynamicProgramming/Minimum sum partition new file mode 100644 index 00000000..2ab1d134 --- /dev/null +++ b/DynamicProgramming/Minimum sum partition @@ -0,0 +1,64 @@ +// Partition a set into two subsets such that the difference of subset sums is minimum + +import java.util.*; +import java.lang.*; +import java.io.*; +class GFG + { + public static void main (String[] args) + { + Scanner sc=new Scanner(System.in); + int t=sc.nextInt(); + while(t-->0) + { + int n=sc.nextInt(); + int arr[]=new int[n]; + int sum=0; + for(int i=0;i Date: Wed, 3 Jun 2020 15:19:55 +0530 Subject: [PATCH 2/2] Update Minimum sum partition Added some test cases for better understanding. --- DynamicProgramming/Minimum sum partition | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/DynamicProgramming/Minimum sum partition b/DynamicProgramming/Minimum sum partition index 2ab1d134..3763d5bd 100644 --- a/DynamicProgramming/Minimum sum partition +++ b/DynamicProgramming/Minimum sum partition @@ -1,5 +1,19 @@ // Partition a set into two subsets such that the difference of subset sums is minimum +/* +Input: arr[] = {1, 6, 11, 5} +Output: 1 +Explanation: +Subset1 = {1, 5, 6}, sum of Subset1 = 12 +Subset2 = {11}, sum of Subset2 = 11 + +Input: arr[] = {36, 7, 46, 40} +Output: 23 +Explanation: +Subset1 = {7, 46} ; sum of Subset1 = 53 +Subset2 = {36, 40} ; sum of Subset2 = 76 + */ + import java.util.*; import java.lang.*; import java.io.*;