Subject Computer Science Data Structures and Algorithms


Devise an algorithm to decide whether a list of integers can be divided into two smaller lists of equal sum. For instance,
[1, 1, 1,2, 2, 2, 3,3, 4, 5,16]can be fairly divided into [1, 1, 1, 2, 2, 2, 3, 3, 5] and [4, 16].
However,[4, 4, 8, 10,14]cannot be fairly divided.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

The solving idea is quite straightforward: if the sum of all elements of the array is odd, then we can’t divide the array into two subsets with equal sum; so a necessary condition is to have an even sum.
Then we can recursively try to solve the calculation of a subset with elements that sum to S/2, where S is the sum of all elements of the array. This can be achieved by trying at each step if we can include or not the last element into the target sum....

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

The Longest Increasing Subsequence Problem
Homework Solution
Computer Science
Longest Increasing Subsequence
Running Time
Get help from a qualified tutor
Live Chats