Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started