Expt 5a
Expt 5a
UID: 2024800052
Experiment No. 5A
AIM:
Program 1
PROBLEM The cost of stock on each day is given in an array A[] of size N.
STATEMENT :
Day 1 price in first location, day 2 price in second location etc. Find all
the days on which you buy and sell the stock any number of time so that
in between those days your profit is maximum.A new transaction can
only start after previous transaction is complete. Person can hold only
one share at a time.
Create class Stock that has name of stock and array of prices. Also it
has input method that initialises the predicted price of the stock in an
array of length N.
Create class Transaction that is sub class of Stock class. It has method
findMaximumProfit method.
RESULT:
CONCLUSION:
The problem is solved using a greedy approach, where we buy at local
minima and sell at local maxima to maximize profit. Multiple transactions
are allowed, ensuring we capture every price rise. The output provides total
profit along with specific buy and sell days.