Looking for algoritm to the partition problem C

  • Thread starter Thread starter transgalactic
  • Start date Start date
  • Tags Tags
    Partition
Click For Summary

Discussion Overview

The discussion revolves around the implementation of a recursive algorithm to solve the partition problem, which involves determining whether an array of integers can be divided into two groups with equal sums. The focus is on constraints regarding the use of loops and pointers in the solution.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant requests a function that determines if an array can be partitioned into two groups with equal sums, specifying that it must be recursive without loops.
  • Another participant questions the necessity of recursion and the restriction against using pointers.
  • A third participant suggests that the requirement for recursion may stem from educational practices in computer science, implying that such constraints may not reflect practical programming needs.
  • A later reply asks for clarification on how to retain calculated values between recursive calls without using references or pointers, suggesting alternatives like member variables or static/global variables.

Areas of Agreement / Disagreement

Participants express differing views on the constraints of the problem, particularly regarding the necessity of recursion and the prohibition of pointers. The discussion remains unresolved with multiple competing perspectives on the implementation details.

Contextual Notes

Participants have not reached a consensus on the appropriateness of the constraints imposed on the problem, and there are unresolved questions about how to manage state in a purely recursive context without pointers.

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?
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 45 ·
2
Replies
45
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K