Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You have an array of integers with length N. (For testing use 10, 20, and 30). The numbers in thearray are consecutive starting with 1.

image text in transcribed

You have an array of integers with length N. (For testing use 10, 20, and 30). The numbers in thearray are consecutive starting with 1. Graders will use other values for grading, so your solution must work for other test cases. int N = 12; int[]data ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int mod = 5;//total is 78, 78 mod 5 is 3 Your goal is to minimize the total of all array elements in the list when modded by a number (variable name mod). For instance, if N is 12 and mod is 5, you would add all elements in the array and mod the total by 5. Initially (with no alterations to the array) the total would be 78 and the modded value would be 3. Your approach to finding the lowest modded value (regardless of the actual total) will need to be recursive. If possible, memoize for 5 extra points. You will be working on adjacent pairs. You will start with the first two pairs. Then you will move your index up two places and work with the next pair. Both values in a pair can have a difference of at most 2. For each pair, you subtract or add to both numbers. That gives you four possibilities: [index]++, [index + 1]++[index]--, [index+1]++[index]++, [index+1]-- or instance, for the pair you are currently indexing, you might add one to the first element and subtract one the second element (index, index+1) You have an array of integers with length N. (For testing use 10, 20, and 30). The numbers in thearray are consecutive starting with 1. Graders will use other values for grading, so your solution must work for other test cases. int N = 12; int[]data ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int mod = 5;//total is 78, 78 mod 5 is 3 Your goal is to minimize the total of all array elements in the list when modded by a number (variable name mod). For instance, if N is 12 and mod is 5, you would add all elements in the array and mod the total by 5. Initially (with no alterations to the array) the total would be 78 and the modded value would be 3. Your approach to finding the lowest modded value (regardless of the actual total) will need to be recursive. If possible, memoize for 5 extra points. You will be working on adjacent pairs. You will start with the first two pairs. Then you will move your index up two places and work with the next pair. Both values in a pair can have a difference of at most 2. For each pair, you subtract or add to both numbers. That gives you four possibilities: [index]++, [index + 1]++[index]--, [index+1]++[index]++, [index+1]-- or instance, for the pair you are currently indexing, you might add one to the first element and subtract one the second element (index, index+1)

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Critically evaluate the experiential learning theory.

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago