
-check this code then, In python 3 make a code that shows the performance curve of the
1. Approach: Non recursive:
//include necessary header files
#include <iostream>
using namespace std;
//main function
int main()
{
int days,buy_on_this_day ,sell_on_this_day;
//get number of days as input from user
cout<<"Enter number of days: ";
cin>>days;
int stock_price[days];
for(int i=0;i<days;i++)
{ cout<<"Enter stock_price";
cin>>stock_price[i];
}
int i=0;
for(int i=0;i<days-1;i++)
{
//comparing current price with next day price and finding the minima
while(i<days-1 && stock_price[i+1]<=stock_price[i])
i++;
if(i==days-1)
break;
buy_on_this_day =i++;
while(i<days && stock_price[i]>= stock_price[i-1])
i++;
sell_on_this_day =i-1;
cout<<buy_on_this_day <<" : index of the change before we buy"<<endl;
cout<<sell_on_this_day<<" :index of the change before we sell"<<endl;
}
int profit;
int maxim =0;
int minSofar = stock_price[0];
for(int i=0;i<days;i++)
{ //calculating the min, profit and max profit
minSofar = min(minSofar, stock_price[i]);// update min s
profit= stock_price[i]-minSofar; // update profit
maxim = max(maxim,profit);// update maximum profit
}
cout<<"Maximum Profit: "<<maxim;
}
//2.APproach:Recurrsive:
//include necessary header files
#include <iostream>
using namespace std;
//recurrsive function to find max profit
int maxPro(int stock_price[], int starting_day, int last_day)
{
if (last_day <= starting_day)
return 0;
int maximum_profit = 0;
for (int i = starting_day; i < last_day; i++)
{
for (int j = i + 1; j <= last_day; j++)
{
if (stock_price[j] > stock_price[i])
{
//update profit
int pro = (stock_price[j] - stock_price[i]) + maxPro(stock_price, starting_day, i - 1) + maxPro(stock_price, j + 1, last_day);
//update maximum profit
maximum_profit = max(maximum_profit, pro);
}
}
}
return maximum_profit;
}
//main function
int main()
{ //declare variables
int days,buy_on_this_day ,sell_on_this_day ;
//get days and stock price as input
cout<<"Enter number of days: ";
cin>>days;
int stock_stock_price[days];
for(int i=0;i<days;i++)
{ cout<<"Enter stock price";
cin>>stock_stock_price[i];
}
int ans =maxPro(stock_stock_price,0,days-1);
cout<<"max profit: "<<ans

Step by stepSolved in 2 steps

- C++ Code: You will implement the following functions: /** * Reads from standard input a list of Short Tandem Repeat (STRs) * and their known counts for several individuals * * @param nameSTRs the STRs (eg. AGAT, AATG, TATC) * @param nameIndividuals the names of individuals (eg. Alice, Bob, Charlie) * @param STRcounts the count of the longest consecutive occurrences of each STR in the DNA sequence for each individual * @pre nameSTRs, nameIndividuals, and nameSTRs are empty * @post nameSTRs, nameIndividuals and STRcounts are populated with data read from stdin **/ void readData(vector<string>& nameSTRs, vector<string>& nameIndividuals, vector<vector<int>>& STRcounts) For example, consider the input: 3 AGAT AATG TATC Alice 5 2 8 Bob 3 7 4 Charlie 6 1 5 It shows, in the first line, the number of STRs followed by the names of those STRs, which will be populated into the vector nameSTRs. The remaining lines contain data for a number of individuals. Their…arrow_forwardC++ languagearrow_forwardPYTHON Problem Statement Given a list of numbers (nums), for each element in nums, calculate how many numbers in the list are smaller than it. Write a function that does the calculation and returns the result (as a list). For example, if you are given [6,5,4,8], your function should return [2, 1, 0, 3] because there are two numbers less than 6, one number less than 5, zero numbers less than 4, and three numbers less than 8. Sample Input smaller_than_current([6,5,4,8]) Sample Output [2, 1, 0, 3]arrow_forward
- C++ The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version of the binary search algorithm. The program should prompt Y / y to continue searching and N / n to discontinue. If an item is found in the list display the following message: x found at position y else: x is not in the list Use the following list of integers when testing your program: 2, 6, 8, 13, 25, 33, 39, 42, 53, 58, 61, 68, 71, 84, 97arrow_forwardAlert: Don't submit AI generated answer and please submit a step by step solution and detail explanation for each steps. Write a python program using functionsarrow_forwardPython question Application: Big-O Notation (Q8-11) For each of the time complexities in this segment give the tightest bound in terms of a simple polylogarithmic function using big-O notation. Note: use the ‘^’ symbol to indicate exponents, i.e., write O(n^2) for O(n2). Question 8 (Big-O Notation 1) T(n) = n2+ log n + n Question 9 (Big-O Notation 2) T(n) = n/3 + 4 log n + 2n log(n) Question 10 (Big-O Notation 3) T(n) = 7n5 + 2n Question 11 (Big-O Notation 4) T(n) = (n%5) + 12,000arrow_forward
- Create a flowchart for this program in c++, #include <iostream>#include <vector> // for vectors#include <algorithm>#include <cmath> // math for function like pow ,sin, log#include <numeric>using std::vector;using namespace std;int main(){ vector <float> x, y;//vector x for x and y for y float x_tmp = -2.5; // initial value of x float my_function(float x); while (x_tmp <= 2.5) // the last value of x { x.push_back(x_tmp); y.push_back(my_function(x_tmp)); // calculate function's value for given x x_tmp += 1;// add step } cout << "my name's khaled , my variant is 21 ," << " my function is y = 0.05 * x^3 + 6sin(3x) + 4 " << endl; cout << "x\t"; for (auto x_tmp1 : x) cout << '\t' << x_tmp1;//printing x values with tops cout << endl; cout << "y\t"; for (auto y_tmp1 : y) cout << '\t' << y_tmp1;//printing y values with tops…arrow_forwardc programming Task 3: Complete armstrong_task3.c by implementing armstrong_recursive function. int armstrong_recursive (int arm); It performs same operation as in Task 1, however in a recursive manner. A number to be checked whether it is armstrong or not is given as an input and the function returns the summation of the digits. If the returned value is equal to the given input value then it is an armstrong number.arrow_forwardComplete this code using Python m1 = [] #Matrix 1m2 = [] #Matrix 2#Write a function that will return the addition of Matrix A and B.#Create a new matrix C that will hold the addtion result of Matrix A and B (A+B).#Return the resultant matrix Cdef addMatrix(A,B):#Write your code here#Write a function that will return the subtraction of Matrix B from A.#Create a new matrix C that will hold the substraction result of Matrix B from A (A-B).#Return the resultant matrix Cdef subsMatrix(A,B):#Write your code here#Write a function that will return the multiplication of Matrix A and B.#Create a new matrix C that will hold the multiplication result of Matrix A and B (A*B).#Keep in mind,in order to perform matrix multiplication, the number of columns in Matrix A must be equal to the number of columns in Matrix B. #Return the resultant matrix Cdef multipyMatrix(A,B):#Write your code here#Write a function that will transform matrix A to the transpose of matrix A.#The transpose of a matrix means…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





