Question: Problem 6 . ImportExport ( A , B ) Input: Two arrays A [ 0 . . . n 1 ] and B [ 0

Problem 6. ImportExport(A,B)
Input: Two arrays A[0... n 1] and B[0... n 1], both of length n, representing the prices of tulips in
country A and country B at different times, respectively. All entries in both arrays are positive integers.
Output: Return the maximum possible profit, defined as:
max
j>i {B[j] A[i]}
or return 0 if all such B[j] A[i] are negative. You only need to return the value of the maximum profit,
not the actual indices i and j.
Example:
Given the input:
A =[40,18,20,25,12,13,19,20,5,7,3]
B =[15,50,5,30,34,19,28,33,20,20,20]
The maximum possible profit is achieved by buying tulips at time i =4(when A[4]=12) and selling them
at time j =7(when B[7]=33), which gives a profit of:
B[7] A[4]=3312=21
Therefore, the output is 21.
Give pseudocode for a recursive O(n)-time algorithm for ImportExport(A,B).
Give pseudocode for a O(n)-time dynamic programming algorithm for ImportExport(A,B).
Solution. The solution to Problem 6 goes here.

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 Programming Questions!