SlideShare a Scribd company logo
1 of 16
World Series Problem : using
dynamic programming approach
Abhinav Kumar Singh
Introduction
 The World Series is a seven-game series that terminates as soon as
either team wins four games.
 The World Series problem allowed us to see the power of dynamic
programming to compute a result iteratively from very simple rules,
filling a table of partial results that leads to a complete answer.
THE WORLD SERIES PROBLEM
 Consider a tournament in which two teams A and B compete in no more than
2n -1 games, with the winner being the first team to win n times. We assume
that there are no tied games, that the results of each match are independent,
and that there is a constant chance p that team A will win and hence a constant
probability q = 1 -p that team B would win for every given match.
Implementation
 Given that in a single contest between team A and team B, the
probability team A wins is p, (and the probability that team B wins is
1-p, so we are precluding ties), what is the probability in i+j games
played, that team A will win i games and team B will win j games. Let
this value be denoted by the function p(i,j).
Implementation
 An alternative way to solve the problem involves dynamic
programming. In order to obtain the dynamic programming
solution, we must first develop a recursive formula for the function
p(i,j). In order for team A to have won i games and team B to have
won j games, before the last game, either A won i and B won j-1 OR
A won i-1 and B won j. Here is a recursive formula that captures that
reasoning:
 p(i, j) = p(i, j - 1)*(1 - p) + p(i -1, j)* p
Now, instead of actually using recursion in our code to figure this out, we can
convert our algorithm into dynamic programming by creating a two-dimensional
array that stores the answers to all necessary recursive calls.
Algorithm (Code)
public static int WS(int i, int j, double p)
{
double[][] prob = new double[i+1][j+1];
prob[0][0] = 1;
// Fill in probabilities for team A sweeping. for (int Awin=1; Awin<=i; Awin++) prob[Awin][0] =
p*prob[Awin-1][0];
// Probabilities for team B sweeping for (int Bwin=1; Bwin<=j; Bwin++) prob[0][Bwin] = (1-
p)*prob[0][Bwin-1];
// Here's where we fill in the table, using the recursive
// formula.
for (int Awin=1; Awin<=i; Awin++)
for (int Bwin=1; Bwin<=j; Bwin++)
prob[Awin][Bwin] = p*prob[Awin-1][Bwin] + (1-p)*prob[Awin][Bwin-1];
// Here's our answer. return prob[Awin][Bwin]; }
The World Series
Example of Dynamic Programming
 The teams A and B play in not more than 2n- 1 games. assume
that
 There are no tied games
 the probability of winning by team A is p
 the team B wins with q = 1 – p.
 P(i, j) is the probability that the team A will win if it gets i more
victories and the team B will win if it gets j more victories.
The World Series…
 For example, before the first game off the series the probability that
team A will be the overall winner is P(n, n): both teams still need n
victories.
 If team A has already won all the matches it needs, then it is of
course certain that they will win the series:
P(0, i) = 1, 1 ≤ i ≤ n.
 Similarly, P(i, 0) = 0, 1 ≤ i ≤n.
 Finally, since team A wins any given match with probability p and
loses it with probability q,P(i, j) = ?
The World Series…
 P(i; j)=pP(i - 1; j) + qP(i; j-1); i≥1;j≥1
function P(i; j)
if i=0 then return 1
else if j = 0 then return 0
else return pP(i - 1; j) + qP(i; j-1)
 Let T(k) be the time required to compute P(i; j) where k = i + j T(1) =
c
T(k) ≤2T(k; 1)+d; k > 1
The World Series…
 T(k) ≤ 4T(k-2) + 2d+d; k > 2
...
≤2k-¹T(1) +(2k-2 +2k-3+...+2+ 1)d
= 2k-1c +(2k-1-1)d
= 2k(c/2+d/2) – d
→ T(k) € 0(2)
The World Series…
Function P(i, j)
if i=0 then return 1
else if j = 0 then return 0
else return pP(i-1, j) + qP(i, j - 1)
Example
 Dodgers and Yankees are playing the World Series in which either team needs to win n games
first. (number of maximum game=2n-1)
 - Suppose that each team has a 50% chance of winning any particular game. - Let P(i, j) be the
probability that if Dodgers needs i games to win, and Yankees needs j games, Dodgers will
eventually win the Series.
 - Ex: P(2, 3) = 11/16
 - Compute P(i, j) (0 <= i, j <= n) for an arbitrary n.
 P(0,1)=1(Win), Yankees W
 P(0,2)=1(Win), Yankees WW
 …
 P(1,0)=0(Lose), Yankees L
 P(2,0)=0(Lose), Yankees LL
 P(2,2)
THANK YOU

More Related Content

Similar to World Series Problem

Dynamic1
Dynamic1Dynamic1
Dynamic1
MyAlome
 

Similar to World Series Problem (20)

Binomial_Coefficient_and_World_series_problem_using_Dynamic_Programming.pptx
Binomial_Coefficient_and_World_series_problem_using_Dynamic_Programming.pptxBinomial_Coefficient_and_World_series_problem_using_Dynamic_Programming.pptx
Binomial_Coefficient_and_World_series_problem_using_Dynamic_Programming.pptx
 
Game theory
Game theoryGame theory
Game theory
 
Papoulis%20 solutions%20manual%204th%20edition 1
Papoulis%20 solutions%20manual%204th%20edition 1Papoulis%20 solutions%20manual%204th%20edition 1
Papoulis%20 solutions%20manual%204th%20edition 1
 
6e-ch4.ppt
6e-ch4.ppt6e-ch4.ppt
6e-ch4.ppt
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Dynamic1
Dynamic1Dynamic1
Dynamic1
 
Cs262 2006 lecture6
Cs262 2006 lecture6Cs262 2006 lecture6
Cs262 2006 lecture6
 
Teori automata lengkap
Teori automata lengkapTeori automata lengkap
Teori automata lengkap
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
 
Stats chapter 8
Stats chapter 8Stats chapter 8
Stats chapter 8
 
Stats chapter 8
Stats chapter 8Stats chapter 8
Stats chapter 8
 
Game throy
Game throyGame throy
Game throy
 
Volleyball analytics: Modeling volleyball using Markov chains
Volleyball analytics: Modeling volleyball using Markov chainsVolleyball analytics: Modeling volleyball using Markov chains
Volleyball analytics: Modeling volleyball using Markov chains
 
Polynomials.pdf
Polynomials.pdfPolynomials.pdf
Polynomials.pdf
 
Unit II B - Game Theory
Unit II B - Game TheoryUnit II B - Game Theory
Unit II B - Game Theory
 
Number theory - Prime Numbers & GCD Algorithms
Number theory - Prime Numbers & GCD AlgorithmsNumber theory - Prime Numbers & GCD Algorithms
Number theory - Prime Numbers & GCD Algorithms
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Tugas akhir modul 5 bilangan eva novianawati h.
Tugas akhir modul 5 bilangan eva novianawati h.Tugas akhir modul 5 bilangan eva novianawati h.
Tugas akhir modul 5 bilangan eva novianawati h.
 
probability and statistics
probability and statisticsprobability and statistics
probability and statistics
 

More from VivekRajawat9 (7)

Communication
CommunicationCommunication
Communication
 
Generating Test Cases
Generating Test CasesGenerating Test Cases
Generating Test Cases
 
5g Cellular Wireless Network.pptx
5g Cellular Wireless Network.pptx5g Cellular Wireless Network.pptx
5g Cellular Wireless Network.pptx
 
Electronic mail protocols and operations
 Electronic mail protocols and operations Electronic mail protocols and operations
Electronic mail protocols and operations
 
Architecture Security in VANET
Architecture Security in VANET Architecture Security in VANET
Architecture Security in VANET
 
Routing Protocols
Routing ProtocolsRouting Protocols
Routing Protocols
 
DEEPANSHU_PPT.pptx
DEEPANSHU_PPT.pptxDEEPANSHU_PPT.pptx
DEEPANSHU_PPT.pptx
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

World Series Problem

  • 1. World Series Problem : using dynamic programming approach Abhinav Kumar Singh
  • 2. Introduction  The World Series is a seven-game series that terminates as soon as either team wins four games.  The World Series problem allowed us to see the power of dynamic programming to compute a result iteratively from very simple rules, filling a table of partial results that leads to a complete answer.
  • 3. THE WORLD SERIES PROBLEM  Consider a tournament in which two teams A and B compete in no more than 2n -1 games, with the winner being the first team to win n times. We assume that there are no tied games, that the results of each match are independent, and that there is a constant chance p that team A will win and hence a constant probability q = 1 -p that team B would win for every given match.
  • 4. Implementation  Given that in a single contest between team A and team B, the probability team A wins is p, (and the probability that team B wins is 1-p, so we are precluding ties), what is the probability in i+j games played, that team A will win i games and team B will win j games. Let this value be denoted by the function p(i,j).
  • 5. Implementation  An alternative way to solve the problem involves dynamic programming. In order to obtain the dynamic programming solution, we must first develop a recursive formula for the function p(i,j). In order for team A to have won i games and team B to have won j games, before the last game, either A won i and B won j-1 OR A won i-1 and B won j. Here is a recursive formula that captures that reasoning:  p(i, j) = p(i, j - 1)*(1 - p) + p(i -1, j)* p
  • 6. Now, instead of actually using recursion in our code to figure this out, we can convert our algorithm into dynamic programming by creating a two-dimensional array that stores the answers to all necessary recursive calls.
  • 7. Algorithm (Code) public static int WS(int i, int j, double p) { double[][] prob = new double[i+1][j+1]; prob[0][0] = 1; // Fill in probabilities for team A sweeping. for (int Awin=1; Awin<=i; Awin++) prob[Awin][0] = p*prob[Awin-1][0]; // Probabilities for team B sweeping for (int Bwin=1; Bwin<=j; Bwin++) prob[0][Bwin] = (1- p)*prob[0][Bwin-1]; // Here's where we fill in the table, using the recursive // formula. for (int Awin=1; Awin<=i; Awin++) for (int Bwin=1; Bwin<=j; Bwin++) prob[Awin][Bwin] = p*prob[Awin-1][Bwin] + (1-p)*prob[Awin][Bwin-1]; // Here's our answer. return prob[Awin][Bwin]; }
  • 8. The World Series Example of Dynamic Programming  The teams A and B play in not more than 2n- 1 games. assume that  There are no tied games  the probability of winning by team A is p  the team B wins with q = 1 – p.  P(i, j) is the probability that the team A will win if it gets i more victories and the team B will win if it gets j more victories.
  • 9. The World Series…  For example, before the first game off the series the probability that team A will be the overall winner is P(n, n): both teams still need n victories.  If team A has already won all the matches it needs, then it is of course certain that they will win the series: P(0, i) = 1, 1 ≤ i ≤ n.  Similarly, P(i, 0) = 0, 1 ≤ i ≤n.  Finally, since team A wins any given match with probability p and loses it with probability q,P(i, j) = ?
  • 10. The World Series…  P(i; j)=pP(i - 1; j) + qP(i; j-1); i≥1;j≥1 function P(i; j) if i=0 then return 1 else if j = 0 then return 0 else return pP(i - 1; j) + qP(i; j-1)  Let T(k) be the time required to compute P(i; j) where k = i + j T(1) = c T(k) ≤2T(k; 1)+d; k > 1
  • 11. The World Series…  T(k) ≤ 4T(k-2) + 2d+d; k > 2 ... ≤2k-¹T(1) +(2k-2 +2k-3+...+2+ 1)d = 2k-1c +(2k-1-1)d = 2k(c/2+d/2) – d → T(k) € 0(2)
  • 12.
  • 13. The World Series… Function P(i, j) if i=0 then return 1 else if j = 0 then return 0 else return pP(i-1, j) + qP(i, j - 1)
  • 14.
  • 15. Example  Dodgers and Yankees are playing the World Series in which either team needs to win n games first. (number of maximum game=2n-1)  - Suppose that each team has a 50% chance of winning any particular game. - Let P(i, j) be the probability that if Dodgers needs i games to win, and Yankees needs j games, Dodgers will eventually win the Series.  - Ex: P(2, 3) = 11/16  - Compute P(i, j) (0 <= i, j <= n) for an arbitrary n.  P(0,1)=1(Win), Yankees W  P(0,2)=1(Win), Yankees WW  …  P(1,0)=0(Lose), Yankees L  P(2,0)=0(Lose), Yankees LL  P(2,2)