Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.8k
Implemented Partition Problem, Recursive problem#1582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Implemented Partition Problem, Recursive problem#1582
Uh oh!
There was an error while loading.Please reload this page.
Conversation
vedas-dixit commentedOct 28, 2023
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
appgurueu left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think this should be categorized as "Recursive" rather than "Backtracking". One definition ofBacktracking 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, andabandons 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 anoptimization problem.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
vedas-dixit commentedOct 29, 2023
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
vedas-dixit commentedNov 5, 2023
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 topartition - 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).
vedas-dixit commentedNov 5, 2023
I appreciate your feedback@appgurueu |
appgurueu left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
(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 justnums as a parameter, and an inner function, which takes justindex andtarget.)
Describe your change:
Checklist:
Example:
UserProfile.jsis allowed butuserprofile.js,Userprofile.js,user-Profile.js,userProfile.jsare notFixes: #{$ISSUE_NO}.