java - Balancing pebbles problem -
i have stumbled upon problem before, balancing problem. program takes in array of integers of size n. program determines if array of integers can split 2 equal parts, sums of integers in each half being equal.
ex. 1 2 3 8 10 4
in which, program returns true, meaning can split 2 halves 14 in each
i know concerned combinations/permutations , i'm not @ them. i've managed think of brute force method. can solved using other methods? more efficient algorithms maybe?
a step step solution helpful. thank much
this partition problem can readily seen equivalent subset sum problem , knapsack problem. np-complete, , thought can't appreciably better exhaustive listing of combinations.
you can check possible ways readily: each element, it's either in left half or right half.
Comments
Post a Comment