Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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++
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 110tStep 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