Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN C AND HAVE GOOD COMMENTS You have worked hard to collect snippets of stock data for training an AI to predict markets for

CODE IN C AND HAVE GOOD COMMENTS

You have worked hard to collect snippets of stock data for training an AI to predict markets for day trading purposes. However, in a bout of sleepless rage over friendships, a colleague wrote a program that sorted all the data in each snippet, thereby ruining your dream of making billions in the stock market. There is still hope! You plan on utilizing the partial information you gathered to help recover the original data collected by writing data recovery program. The data you had initially stored was the value of a stock on a particular day (at fixed intervals) and the absolute change in the stock value (between the fixed intervals). Luckily, your sort method only sorted the stock values with respect to each other and the changes with respect to each other. You quickly realize that the number of valid data arrangements can be quite large. For this assignment your program should output only the number of possible data arrangements give the unsorted list of values and the unsorted list of price differences. Suppose the values of a particular section were 1, 2, 3, 5, and 4. Then the absolute differences would be 1, 1, 2, and 1. The sorted values would become 1, 2, 3, 4, and 5. While the sorted absolute differences would be 1, 1, 1, and 2.

Input Specification The input will begin with an integer n (n 12), number data points for a given data set. The next line will each contain n space separated integers, ai (1 ai 10,000), representing the data points for the stock value on the given day. The next line contains n 1 space separated integers, di (0 di 9,999), representing the absolute differences between stock values between the fixed intervals.

Output Specification The program should output the number of valid distinct arrangements of ai values that complies with the input given.

Store the values you have used at each index in the recursive function to avoid reusing a value that was already used. This used array will need to be allocated and initialized in each recursive call.

image text in transcribed

image text in transcribed

Input Output Example Input Output 1 2 3 4 5 1112 11122 0011 Explanation Case 1 There are 4 different arrangements of values that satisfies the given differences Values (1, 2, 3, 5, 4) => differences (1, 1, 2, 1) Values (2, 1, 3, 4, 5) => differences (1, 2, 1, 1) Values (4, 5, 3, 2, 1) => differences (1, 2, 1, 1) Values (5, 4, 3, 1, 2) => differences (1, 1, 2, 1) Note 1: Although the difference order is repeated the values are different between the first and fourth order and the second and third order. Note 2: that even though the first order is the reverse of the third order. The two orders are consider different. This is because the value of the stock is different at the different times. Visually Ai il TIIL Case 2 There are 3 different orders (2, 1, 1, 1, 2) => (1, 0, 0, 1) (1, 2, 2, 1, 1) => (1, 0, 1, 0) (1, 1, 2, 2, 1) => (0, 1, 0, 1) Visually T1 SAL B BA Note that although you could rearrange the 2's and the l's amongst themselves the actual values of the stock would not change over time. i.e. (21, 11, 12, 13, 22) is equivalent to (22, 11, 12, 13, 2.). Input Output Example Input Output 1 2 3 4 5 1112 11122 0011 Explanation Case 1 There are 4 different arrangements of values that satisfies the given differences Values (1, 2, 3, 5, 4) => differences (1, 1, 2, 1) Values (2, 1, 3, 4, 5) => differences (1, 2, 1, 1) Values (4, 5, 3, 2, 1) => differences (1, 2, 1, 1) Values (5, 4, 3, 1, 2) => differences (1, 1, 2, 1) Note 1: Although the difference order is repeated the values are different between the first and fourth order and the second and third order. Note 2: that even though the first order is the reverse of the third order. The two orders are consider different. This is because the value of the stock is different at the different times. Visually Ai il TIIL Case 2 There are 3 different orders (2, 1, 1, 1, 2) => (1, 0, 0, 1) (1, 2, 2, 1, 1) => (1, 0, 1, 0) (1, 1, 2, 2, 1) => (0, 1, 0, 1) Visually T1 SAL B BA Note that although you could rearrange the 2's and the l's amongst themselves the actual values of the stock would not change over time. i.e. (21, 11, 12, 13, 22) is equivalent to (22, 11, 12, 13, 2.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions