Question: Hindsight is 2 0 2 0 when it comes to investing in Pokemon cards. Suppose you're given CARDDNC ( P [ 1 , dots, n
Hindsight is when it comes to investing in Pokemon cards. Suppose you're given CARDDNCdots,:
your code here
Give a brief verbal explanation for why your algorithm works, and why it runs
in time Yes there is a faster way of doing this problem.
an array dots, where is the price of a certain card on day The goal is to
find the best days to buy and sell in order to maximize your profit. The return value
of your algorithms should be the profit made, ie the difference between the selling
price and the buying price.
You may assume that you're only buying and selling one card, the price doesn't change
during a given day, and that the card needs to be bought before it is sold. In other
words, you are trying to maximize over all pairs of indices i and where
For example, if the array of prices is
the maximum profit is which is achieved when you buy on day and sell on day
You can't make a profit of because comes after
For both parts below, write down an algorithm in pseudocode.
a Design a brute force algorithm for solving this problem. Your algorithm should
be of the form:
CARDBRUTEdots,:
your code here
In terms of bigO notation, how long does your algorithm take?
b Use divide and conquer to design an algorithm that runs in time
Hint: see the maximum subarray problem from class Your algorithm should be
of the form:
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
