Online Algorithms
And their Applications
Definition
• In computer science, an online algorithm is one that can process its
input piece-by-piece in a serial fashion, i.e., in the order that the input
is fed to the algorithm, without having the entire input available from
the start.
• Online algorithms may produce the results that are not optimal as it
doesn’t have the complete input.
Offline Algorithms
• An offline algorithm is one which is given the whole problem data
from the beginning and is required to output an answer which solves
the problem at hand.
• Offline algorithms produce the optimal solution as it is given the
complete input.
Competitive Analysis
• Competitive analysis is a method of analyzing online algorithms, in
which the performance of an online algorithm is compared to the
performance of an optimal offline algorithm.
• The competitive ratio of an algorithm, is defined as the worst-case
ratio of its cost divided by the optimal cost, over all possible inputs.
• The competitive ratio of an online problem is the best competitive
ratio achieved by an online algorithm.
Secretary Problem
• The secretary problem is one of many names for a famous problem of the
optimal stopping theory. The problem has been studied extensively in the fields
of applied probability, statistics, and decision theory. It is also known as the
marriage problem, the sultan's dowry problem, the best choice problem, etc.
Formulation:
• Although there are many variations, the basic problem can be stated as
follows:
• There is a single secretarial position to fill.
• There are n applicants for the position, and the value of n is known.
• The applicants, if seen altogether, can be ranked from best to worst
unambiguously.
Secretary Problem
• The applicants are interviewed sequentially in random order, with each order
being equally likely.
• Immediately after an interview, the interviewed applicant is either accepted or
rejected, and the decision is irrevocable.
• The decision to accept or reject an applicant can be based only on the relative
ranks of the applicants interviewed so far.
• The objective of the general solution is to have the highest probability of
selecting the best applicant of the whole group. This is the same as maximizing
the expected payoff, with payoff defined to be one for the best applicant and zero
otherwise.
Terminology: A candidate is defined as an applicant who, when interviewed, is better than all
the applicants interviewed previously. Skip is used to mean "reject immediately after the
interview".
Secretary Problem
Strategy to solve:
One strategy could be-
Always pick the ith candidate from some predetermined i ϵ [1,N]
P(Success) = 1/N
We can do much better than 1/N by applying the following rule, which yields the
optimal solution:
Interview and reject the first r applicants, for r < N. Accept the very next applicant
that is better than all the first r you interviewed.
P(Success) =P(r)
We will now show that the optimal solution is found by optimizing P(r) by the
standard route of solving:
P’(r) = 0
Secretary Problem
• Solution:
The following diagram will be helpful to visualize the problem:
Let R be the last applicant you will see before you actually start considering
hiring anyone (the last one you're going to reject no matter what). Let the
best applicant of all N, i* occur arbitrarily at n + 1, and N is the total number
of applicants you have the potential to interview. We then can say that i* will
not be chosen unless both of the following conditions are met:
Secretary Problem
1. n ≥ r
2. The highest applicant in [1, n] is the same highest applicant in [1, r]
The probability of this happening for some given n is
This basically stems from the fact that the probability of i* occuring at
n+1 is 1/N and the probability of condition (2) is r/n . We can obtain
P(r) by summing over all possible n ≥ r :
Secretary Problem
By inspecting the expression in the limit as N → ∞, letting
and , we find the following:
So in the limit as N grows in infinitely large, we find that the ratio of
applicants reviewed and rejected to the number of total applicants
approaches x. We see then that solving P’( r ) = 0 for r gives us the
optimal ratio and the probability of success P(roptimal).
Secretary Problem
The ratio of r to N is optimal at 1/e yielding a probability of success of,
coincidentally, 1/e as well. So for N >> 1 the roptimal is nearly N/e,
otherwise it can be found by computing P(r) directly.
Secretary Problem
All Together Now
• The secretary problem is the problem of deciding whether or not one should stick with
what they have or take their chances on something new.
• Examples of secretary problems include finding a husband or wife, hiring a secretary, and
alligator hunting.
• The solution to the secretary problem suggests that the optimal dating strategy is to
estimate the maximum number of people you’re willing to date, (N), and then date
(sqrt{N}) people and marry the next person who is better than all of those.
• In laboratory experiments, people often stop searching too soon when solving secretary
problems. This suggests that the average person doesn’t date enough people prior to
marriage.
• At the end of the day, the secretary problem is a mathematical abstraction and there is
more to finding the “right” person than dating a certain number of people.
Applications: Stock Market
Stock Market
• The market in which shares of publicly held companies are issued and
traded either through exchanges or over-the-counter markets. Also
known as the equity market, the stock market is one of the most vital
components of a free-market economy, as it provides companies with
access to capital in exchange for giving investors a slice of ownership
in the company.
• The stock market makes it possible to grow small initial sums of
money into large ones, and to become wealthy without taking the risk
of starting a business or making the sacrifices that often accompany a
high-paying career.
Stock Market
• Today, most stock market trades are executed electronically, and even
the stocks themselves are almost always held in electronic form, not
as physical certificates.
Stock Market Prediction
• Stock market prediction is the act of trying to determine the future
value of a company stock or other financial instrument traded on an
exchange. The successful prediction of a stock's future price could
yield significant profit. The efficient-market hypothesis suggests that
stock price movements are governed by the random walk hypothesis
and thus are inherently unpredictable. Others disagree and those
with this viewpoint possess myriad methods and technologies which
purportedly allow them to gain future price information.
• Some believe that the prediction of share price is pure speculation
but some believe that there is some mathematics involved.
Use of Algorithm in Stock Prediction
• Online algorithms play an important role in stock prediction.
• We can develop algorithms which can predict future price of stocks to
some extent with some probability of error in prediction.
• Believing that history repeats itself, a potential algorithm for stock
prediction could be developed which gives the output based on the
previous data of stock prices available and generate results.
Use of Algorithm in Stock Prediction
• Is there any algorithm available which could predict the stock price
with 100% accuracy??
Portfolio Management
• The term portfolio refers to any collection of financial assets such as
cash, shares. Portfolios may be held by individual investors and/or
managed by financial professionals, hedge funds, banks and other
financial institutions.
• Portfolio Management is the art and science of making decisions
about investment mix and policy, matching investments to objectives,
asset allocation for individuals and institutions, and balancing risk
against performance.
Vikas Jindal
B.Tech., CSE
IIT Patna
vikasjindal.iitp@gmail.com
Thank You!

Online algorithms and their applications

  • 1.
  • 2.
    Definition • In computerscience, an online algorithm is one that can process its input piece-by-piece in a serial fashion, i.e., in the order that the input is fed to the algorithm, without having the entire input available from the start. • Online algorithms may produce the results that are not optimal as it doesn’t have the complete input.
  • 3.
    Offline Algorithms • Anoffline algorithm is one which is given the whole problem data from the beginning and is required to output an answer which solves the problem at hand. • Offline algorithms produce the optimal solution as it is given the complete input.
  • 4.
    Competitive Analysis • Competitiveanalysis is a method of analyzing online algorithms, in which the performance of an online algorithm is compared to the performance of an optimal offline algorithm. • The competitive ratio of an algorithm, is defined as the worst-case ratio of its cost divided by the optimal cost, over all possible inputs. • The competitive ratio of an online problem is the best competitive ratio achieved by an online algorithm.
  • 5.
    Secretary Problem • Thesecretary problem is one of many names for a famous problem of the optimal stopping theory. The problem has been studied extensively in the fields of applied probability, statistics, and decision theory. It is also known as the marriage problem, the sultan's dowry problem, the best choice problem, etc. Formulation: • Although there are many variations, the basic problem can be stated as follows: • There is a single secretarial position to fill. • There are n applicants for the position, and the value of n is known. • The applicants, if seen altogether, can be ranked from best to worst unambiguously.
  • 6.
    Secretary Problem • Theapplicants are interviewed sequentially in random order, with each order being equally likely. • Immediately after an interview, the interviewed applicant is either accepted or rejected, and the decision is irrevocable. • The decision to accept or reject an applicant can be based only on the relative ranks of the applicants interviewed so far. • The objective of the general solution is to have the highest probability of selecting the best applicant of the whole group. This is the same as maximizing the expected payoff, with payoff defined to be one for the best applicant and zero otherwise. Terminology: A candidate is defined as an applicant who, when interviewed, is better than all the applicants interviewed previously. Skip is used to mean "reject immediately after the interview".
  • 7.
    Secretary Problem Strategy tosolve: One strategy could be- Always pick the ith candidate from some predetermined i ϵ [1,N] P(Success) = 1/N We can do much better than 1/N by applying the following rule, which yields the optimal solution: Interview and reject the first r applicants, for r < N. Accept the very next applicant that is better than all the first r you interviewed. P(Success) =P(r) We will now show that the optimal solution is found by optimizing P(r) by the standard route of solving: P’(r) = 0
  • 8.
    Secretary Problem • Solution: Thefollowing diagram will be helpful to visualize the problem: Let R be the last applicant you will see before you actually start considering hiring anyone (the last one you're going to reject no matter what). Let the best applicant of all N, i* occur arbitrarily at n + 1, and N is the total number of applicants you have the potential to interview. We then can say that i* will not be chosen unless both of the following conditions are met:
  • 9.
    Secretary Problem 1. n≥ r 2. The highest applicant in [1, n] is the same highest applicant in [1, r] The probability of this happening for some given n is This basically stems from the fact that the probability of i* occuring at n+1 is 1/N and the probability of condition (2) is r/n . We can obtain P(r) by summing over all possible n ≥ r :
  • 10.
    Secretary Problem By inspectingthe expression in the limit as N → ∞, letting and , we find the following: So in the limit as N grows in infinitely large, we find that the ratio of applicants reviewed and rejected to the number of total applicants approaches x. We see then that solving P’( r ) = 0 for r gives us the optimal ratio and the probability of success P(roptimal).
  • 11.
    Secretary Problem The ratioof r to N is optimal at 1/e yielding a probability of success of, coincidentally, 1/e as well. So for N >> 1 the roptimal is nearly N/e, otherwise it can be found by computing P(r) directly.
  • 12.
    Secretary Problem All TogetherNow • The secretary problem is the problem of deciding whether or not one should stick with what they have or take their chances on something new. • Examples of secretary problems include finding a husband or wife, hiring a secretary, and alligator hunting. • The solution to the secretary problem suggests that the optimal dating strategy is to estimate the maximum number of people you’re willing to date, (N), and then date (sqrt{N}) people and marry the next person who is better than all of those. • In laboratory experiments, people often stop searching too soon when solving secretary problems. This suggests that the average person doesn’t date enough people prior to marriage. • At the end of the day, the secretary problem is a mathematical abstraction and there is more to finding the “right” person than dating a certain number of people.
  • 13.
  • 14.
    Stock Market • Themarket in which shares of publicly held companies are issued and traded either through exchanges or over-the-counter markets. Also known as the equity market, the stock market is one of the most vital components of a free-market economy, as it provides companies with access to capital in exchange for giving investors a slice of ownership in the company. • The stock market makes it possible to grow small initial sums of money into large ones, and to become wealthy without taking the risk of starting a business or making the sacrifices that often accompany a high-paying career.
  • 15.
    Stock Market • Today,most stock market trades are executed electronically, and even the stocks themselves are almost always held in electronic form, not as physical certificates.
  • 16.
    Stock Market Prediction •Stock market prediction is the act of trying to determine the future value of a company stock or other financial instrument traded on an exchange. The successful prediction of a stock's future price could yield significant profit. The efficient-market hypothesis suggests that stock price movements are governed by the random walk hypothesis and thus are inherently unpredictable. Others disagree and those with this viewpoint possess myriad methods and technologies which purportedly allow them to gain future price information. • Some believe that the prediction of share price is pure speculation but some believe that there is some mathematics involved.
  • 17.
    Use of Algorithmin Stock Prediction • Online algorithms play an important role in stock prediction. • We can develop algorithms which can predict future price of stocks to some extent with some probability of error in prediction. • Believing that history repeats itself, a potential algorithm for stock prediction could be developed which gives the output based on the previous data of stock prices available and generate results.
  • 18.
    Use of Algorithmin Stock Prediction • Is there any algorithm available which could predict the stock price with 100% accuracy??
  • 19.
    Portfolio Management • Theterm portfolio refers to any collection of financial assets such as cash, shares. Portfolios may be held by individual investors and/or managed by financial professionals, hedge funds, banks and other financial institutions. • Portfolio Management is the art and science of making decisions about investment mix and policy, matching investments to objectives, asset allocation for individuals and institutions, and balancing risk against performance.
  • 20.
    Vikas Jindal B.Tech., CSE IITPatna vikasjindal.iitp@gmail.com Thank You!