Question: You are given an array of N price changes for an item in some market. At each price change, you can buy the item, sell
You are given an array of N price changes for an item in some market. At each price change, you can buy the item, sell the item if you already have it or not do anything. Your goal is to make decisions that maximize your overall profit.
Example. prices Output
Explanation.
The maximum profit can be achieved by:
Buying at prices
Skipping prices and prices
Selling at prices
Buying at prices
Selling at prices
The total profit is
Design a backtracking algorithm to solve this problem. Follow the steps below:
A Draw a tree showing how a bruteforce enumeration algorithm enumerates the candidate solutions for the following instance: prices
Clearly show on the tree what each node and edge represent. You dont have to draw the full tree as it might be large. However, you must show the root, the second level in the tree, and the full path to at least two feasible solutions and two infeasible solutions.
B Suggest a backtracking strategy to improve the running time of the bruteforce algorithm.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
