Question: Implement algorithm below in Python. Python code needed not c and c++ Assume you are a merchant. Your aim is to maximize your profit by

Implement algorithm below in Python. Python code needed not c and c++Implement algorithm below in Python. Python code needed not c and c++

Assume you are a merchant. Your aim is to maximize your profit by buying some goods preferably at a low price and then selling them preferably at a higher price afterwards. Assuming that you know the market prices for a given period of time, your goal is to decide when to buy and when to sell in order to maximize your profit. Do not forget that you cannot sell before you buy. (a) 15pts. Design a divide-and-conquer algorithm to solve this problem. (b) 5 pts. Design an algorithm that is not based on the divide-and-conquer approach to solve this problem in linear time. (c) 5pts. Compare these two algorithms in terms of their worst-case time complexity. Example: Input: [10,11,10,9,8,7,9,11] (It means that the market price is 10 t on Day0,11 t on Day1,,11 t on Day7 ) Output: Buy on Day for 7t and sell on Day11 for 11t. Example: Input: [100,110,80,90,110,70,80,80,90] (It means that the market price is 100t on Day0,110t on Day1,,90t on Day8 ) Output: Buy on Day2 for 80t and sell on Day4 for 110t

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!