Answered step by step
Verified Expert Solution
Link Copied!

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.
012345
Example. prices =[1,3,2,8,4,9] Output =12
Explanation.
The maximum profit can be achieved by:
Buying at prices[0]=-1
Skipping prices[1] and prices[2]
Selling at prices[3]=+8
Buying at prices[4]=-4
Selling at prices[5]=+9
The total profit is -1+8-4+9=12.
Design a backtracking algorithm to solve this problem. Follow the steps below:
A. Draw a tree showing how a brute-force enumeration algorithm enumerates the candidate solutions for the following instance: prices =[1,3,2]
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 brute-force algorithm.

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

The nature and importance of the global marketplace.

Answered: 1 week ago