Implemented Partition Problem, Recursive problem#1582
Implemented Partition Problem, Recursive problem#1582raklaptudirm merged 26 commits intoTheAlgorithms:masterfrom
Conversation
|
Hello @appgurueu & @raklaptudirm, Can you guys please review "Tug of war-backtracking problem" that I committed recently and leave a comment if any change or modification is required :) |
…to tug-of-war-backtracking
There was a problem hiding this comment.
I think this should be categorized as "Recursive" rather than "Backtracking". One definition of Backtracking is:
Backtracking is a class of algorithms for finding solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate as soon as it determines that the candidate cannot possibly be completed to a valid solution.
I don't see the emphasized part here. To me, this is just a recursive algorithm which tries all possible ways to partition the set into two subsets, evaluating them and picking the best, solving an optimization problem.
|
I was also thinking of putting it in the "Recursive" Questions but this question is labelled as "Backtracking" so I just followed the trend. |
…to tug-of-war-backtracking
…xit/JavaScript into tug-of-war-backtracking
…emove redundant checks
…xit/JavaScript into tug-of-war-backtracking
|
I've made some necessary changes @appgurueu & @raklaptudirm Changed File Location of "TugOfWar.js" under "Recursive" from "Backtracking" |
appgurueu
left a comment
There was a problem hiding this comment.
Ah, I see the issue now. This does not solve the "tug of war" problem; you are missing the side condition that both sets should have size n/2.
This does solve the "partition" problem (which can be reduced to the 0-1-knapsack problem) however.
I suggest either renaming this to partition - and removing the GfG reference - or fixing the implementation s.t. the subsets each have size n/2 (note: if n is odd, the sizes may differ by one).
…xit/JavaScript into tug-of-war-backtracking
|
I appreciate your feedback @appgurueu |
appgurueu
left a comment
There was a problem hiding this comment.
(Note: Calculating the sum of nums in each recursive call is wasteful. But the implementation is correct, and really "efficiently" solving the problem isn't possible anyways (unless P = NP), so I don't mind terribly much. Ideally you should have an outer function, which takes just nums as a parameter, and an inner function, which takes just index and target.)
Describe your change:
Checklist:
Example:
UserProfile.jsis allowed butuserprofile.js,Userprofile.js,user-Profile.js,userProfile.jsare notFixes: #{$ISSUE_NO}.