(Solved):
Problem 2: Rising Trends (25 marks) Given an array \( P[1 . . n] \) where \( P_{i} \) represents t ...
Problem 2: Rising Trends (25 marks) Given an array \( P[1 . . n] \) where \( P_{i} \) represents the price of a stock on day \( i \), find the length of the longest rising trend. A rising trend is a subsequence of days, beginning on day 1 and not necessarily contiguous, where the price of the stock strictly increases. 1. (7 marks) Given \( P \), define a recurrence relation for \( L_{j} \) which denotes the longest rising trend that begins on day \( j \). 2. Using this recurrence, implement and test a dynamic programming algorithm that: (a) (10 marks) Finds the longest rising trend. (b) (5 marks) Describes the optimal solution. 3. (3 marks) State the order of complexity of your algorithm.