hello, this is part of our task:
definition: an almost balanced partiton of an array is to split an array into 2,
that the sum of the sub-groups are equal, and one one of the groups as 2 more numbers max.
example:
array: 1,2,2,3,5,6,1
sub1: 1,2,2,5 (=10)
sub2: 3,6,1 (=10)
also:
123451 -
1,3,4
1,2,5
no good:
1,2,3,4,10
because one group is bigger then 2 from the other.
(hope you followed so far...)
write a function that gets an array of integers and it's size, - void almost_balanced_partition(int arr[],int size)
and print out 2 groups that are the "almost balanced partition"
of it. the printout of the subgroups will be like this:
for the array of 1,2,2,3,5,6,1 it will print:
{1,2,2,5}
{3,6,1}
if not possible, printout 0.
you can assume that the array is not bigger then 20 numbers, and you can use one more function.
everything have to be in recursion, no loops are allowed.
hope you can help me, we tried to think on a way for to many hours so far...
!IMPORTANT!
i'm not asking for a code.
i'm still trying to figure out how to solve.
i'm asking helps and tips in writing the algorithem not the code!
thanks, and sorry if i was'nt clear on that earlier.
definition: an almost balanced partiton of an array is to split an array into 2,
that the sum of the sub-groups are equal, and one one of the groups as 2 more numbers max.
example:
array: 1,2,2,3,5,6,1
sub1: 1,2,2,5 (=10)
sub2: 3,6,1 (=10)
also:
123451 -
1,3,4
1,2,5
no good:
1,2,3,4,10
because one group is bigger then 2 from the other.
(hope you followed so far...)
write a function that gets an array of integers and it's size, - void almost_balanced_partition(int arr[],int size)
and print out 2 groups that are the "almost balanced partition"
of it. the printout of the subgroups will be like this:
for the array of 1,2,2,3,5,6,1 it will print:
{1,2,2,5}
{3,6,1}
if not possible, printout 0.
you can assume that the array is not bigger then 20 numbers, and you can use one more function.
everything have to be in recursion, no loops are allowed.
hope you can help me, we tried to think on a way for to many hours so far...
!IMPORTANT!
i'm not asking for a code.
i'm still trying to figure out how to solve.
i'm asking helps and tips in writing the algorithem not the code!
thanks, and sorry if i was'nt clear on that earlier.