DP solution/solution.py
prices = [1,2,3,7,5,4,6,9,8,4,5]
prices_diff = [0]*(len(prices)-1)
for i in range(0,len(prices_diff)):
prices_diff[i] = prices[i+1] - prices[i]
A = [0]*(len(prices_diff)+1)
for j in range(1,len(prices_diff)):
if(A[j-1]+prices_diff[j-1]>prices_diff[j-1]):
A[j] = A[j-1]+prices_diff[j-1]
else:
A[j] = prices_diff[j-1]
m = A[0]
for j in range (1,len(A)):
if(m
m = A[j]
print("Maximum profit: ",m)
DP solution/Solutions - Dynamic programming.docx
1. Big-O analysis of the time complexity for the Brute Force strategy
Complexity of the brute-force strategy is O(n2). Suppose the array a has n...