Looking for algoritm to the partition problem C

  • Thread starter Thread starter transgalactic
  • Start date Start date
  • Tags Tags
    Partition
AI Thread Summary
The discussion focuses on creating a recursive function, int partition(int arr[], int size), that determines if an integer array can be split into two groups with equal sums. An example provided illustrates that the array {1,2,2,3,5,6,1} can be divided into two groups, both summing to 10, which would result in the function returning 1. The requirement for recursion without loops and the restriction against using pointers raises questions about how to retain calculated values across recursive calls. The conversation touches on the educational emphasis on recursion in computer science courses, suggesting that while it may not reflect practical programming, it is a common academic exercise. There is also a concern about how to manage state without pointers, hinting at the potential use of static or global variables, although their use in this context remains unclear.
transgalactic
Messages
1,386
Reaction score
0
write a function called
Code:
 int partition(int arr[], int size)
which input an array of integers and decides whether
it is possible to divide the array into two groups
so the sums of both the groups will be equal.
Code:
for example arr = {1,2,2,3,5,6,1}
its could be divided into {2,2,6}  and {1,1,3,5} both of their sums is 10
so they are equal and the function needs to return 1.

the function must be recursive without loops.
you are allowed to use only one external recursive function

and i can't use pointers
i tied to build a code that sums for ranges
but the example shows that there could be a possibility
of two sub sequences mixed with one another
so the range option is not solving this

??
 
Technology news on Phys.org
Why does the method have to be recusive? Why can't you use pointers?
 
Because CS homework always involves recursion - CS teachers still thinks it's cool.
Fortunately almost all CS grads remember nothing they have learned so don't try and use it in the real world.
 
Well then, a little more coded form would help understand the task at hand. For example, since no references or pointers are allowed, how do you intend to retain a calculated value between calls...a member variable or possibly a static or global variable, or are these off limits also?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top