Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the link to solve the problem: Add comments to the steps. Use C++ coding language https://www.onlinegdb.com/ADMCN6-GZ 3 Problem 3: Divide a vector by sum

image text in transcribed

Use the link to solve the problem: Add comments to the steps. Use C++ coding language

https://www.onlinegdb.com/ADMCN6-GZ

3 Problem 3: Divide a vector by sum (40+5 points) In this problem, given a non-empty vector nums that only has positive integers, you are going to find if this vector can be divided into two subsets, such that the sum of elements in both subsets is equal. Any element can only exist in one of the two subsets. For example: - Input: nums ={1,5,11,5}. Output: true. The two subsets are {1,5,5} and {11} - Input: nums ={1,2,3,5}. Output: false. We cannot find two equal sum subsets. The starter code is here: https://onlinegdb. com/ADMCN6-GZ Hint 1: This problem basically reduces to determining if there exists a subset of the vector such that the sum of elements in it is half of the total sum of nums. Hence, you only need to make a small modification of our subset codes in the lecture. Hint 2: Be careful of the integer division. Use double to ensure it is a decimal number if you like. Bonus task ( 5 points): However, if we directly use the modification of our subset codes, there would be an issue, which will cause your codes to be very slow. Can you point it out? Hint: Draw the tree of recursive calls for the following input and then you will see the issue:) nums ={1,1,1,1,1,1,1,1,1,1,1,1} (i.e., 12 ones)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

1. Explain why evaluation is important.

Answered: 1 week ago