Showing posts with label algorithm. Show all posts
Showing posts with label algorithm. Show all posts

Thursday, December 24, 2009

A ball probability question

I was looking for a solution to a ball probability question which is described below. I found this page which exactly describes the same question: http://www.isibang.ac.in/~statmath/problems/august.html. However, it seems the page is not accessible now. So I copied the page and pasted it here. If this incurs any term/license problem, I am more than glad to remove the content.

Suppose Farrah gives you two bags. Bag A, contains 50 Red balls and Bag B, contains 50 Black Balls. She leaves the room asking you to rearrange the balls between the bags in any way you want without discarding any of the balls. She then returns and chooses a bag at random and then from the chosen bag, chooses a ball at random.

Question: Can you find the rearrangement that maximises her chance of choosing a black ball ?



Solution provided by Winners :

  • Soumya bhattacharya
    Clearly,if one bag contains only black balls and the other bag atleast one black ball along with the red balls,then the prabability that Farrah choses a black ball is more than half.

    Again if any of the bags contain equal no. of black and red balls ,then the other bag also contains them in equal number and (if none of them is an empty bag,in which case the probability of Farrah's chosing a black ball is only 1/4) the probability that Farrah choses a black ball is half.As we already have seen an example in which the probability of chosing a black ball is more than half,hence this case can't be the solution.

    So,if an optimal case exist,in that each of the bags must contain unequal numbers of black and red balls.And hence,(as the total no. of black balls= the total no. of the red balls) the proportion of black balls in a bag will be more than half in one bag and less than half,in the other. let 'b' and 'd' denote the total no. of balls in 2 bags and 'a' and 'c' denote the total no. of black balls in them respectively.

    W.L.O.G.,let us assume that a/b < 1/2 and c/d > 1/2.Now if we take out a black and a red ball from the 2nd bag and put them in the first,the probability of chosing a black ball changes from (1/2)*(a/b + c/d) to (1/2)*((a+1)/(b+2) + (c-1)/ (d-2)). Again as a/b < 1/2,hence we have (a+1)/(b+2) > a/b. And as c/d > 1/2, (c-1)/(d-2) > c/d.

    Therefore, by this rearrangement,the probability of chosing a black ball increases.So we do it untill there is no red ball in the bag,which was initially containing d balls.( as there were more black balls initially in this,and we shift equal no. of red and black balls to the other bag.) Now, clearly if we shift all the black balls,leaving only one in the first bag to the bag that contains red balls also,then the ratio of blacks to reds increases in the 2nd bag ,whereas that in the 1st bag remains constant, in effect increasing the probability of chosing a black ball by Farrah.

    So,starting with any arbitrary case we have reached the state of rearrangement, which has the probability of chosing a black ball more than or equal to that arbitrary case.So, we conclude that ,the rearrangement of the balls in which one bag contains only 1 black ball and the other bag contains the rest of the balls is maximum (0.7474).

  • Subhroshekhar Ghosh

    First of all, we claim that the required arrangement is : one black ball in one of the jars and all the other balls in the other jar, when the probability p of getting a black ball turns out to be 1/2*1 + 1/2 * 49/99.

    To, see this, we eliminate the cases 1.all the balls are in one jar (p=1/4) 2.there are equal no. of red and black balls in one jar (and hence in the other jar) (p=1/2).

    We observe that for any labelling of the jars as 1 and 2, p=1/2*p(1)+1/2*p(2) where p(i) is the conditional probability of getting a black ball having chosen the ith jar. Also, as there are equal no. of red and black balls, in any configuration there will be exactly one jar in which no. of red balls >= no. of black balls, hence the conditional probability for that jar <= 1/2. Since we have eliminated cases 1 and 2, we will have it < 1/2.

    Without loss of generality, we call this jar 1 and let it have r red and b black balls. Then p(1)=b/(r+b), b0. We have p(1)<1/2, so we consider 1/2 - p(1) = 1/2 * {(r-b)/(r+b)}. The restrictions imply (r-b)>= 1 and r+b <=99. Therefore, 1/2 - p(1) >= 1/2 * 1/99, so p(1) <= 49/99, equality holds if there are 50 red and 49 black balls in jar 1. The other conditional probability p(2) <= 1, equality holds if all balls in jar 2 are black. Hence, p will be maximised if both of these upper bounds are attained. But they are attained by the configuration mentioned in the beginning. In fact, it is clear from the equality conditions that this configuration is the only one that attains the upper bound.

  • Sunday, January 06, 2008

    Probabilistic algorithms

    Recently, I read some articles which describe probabilistic(randomized) algorithms I have not heard of before. This cluster of algorithms are really interesting. There are four main categories: Monte Carlo algorithms, Las Vegas algorithms, Sherwood algorithms and Numerical approximation algorithms.
    This article(http://www.cs.man.ac.uk/~david/courses/advalgorithms/probabilistic.pdf) describes probabilistic algorithms with concrete examples. It is a good tutorial for newbies.
    Here, I would like to excerpt part of the original article.
    (1) Monte Carlo algorithms
    "Algorithms which always return a result, but the result may not always be correct. We attempt to minimise the probability of an incorrect result, and using the random element, multiple runs of the algorithm will reduce the probability of incorrect results."
    Examples:
    (*)Majority element in an array
    (*)Matrix multiplication(whether A*B=C)
    (*)Testing the primality of numbers
    (*)Deciding set equality
    (2) Las Vegas algorithms
    "Algorithms that never return an incorrect result, but may not produce results at all on some runs. Again, we wish to minimise the probability of no result, and, because of the random element, multiple runs will reduce the probability of no result. "
    Examples:
    (*) Eight Queens Problem
    (*) Factorization of integers
    (3) Sherwood algorithms
    "Algorithms which always return a result and the correct result, but where a random element increases the eciency, by avoiding or reducing the probability of worst-case behaviour. Useful for algorithms which have a poor worst-case behaviour but a good average-case behaviour."
    Examples:
    (*)Quicksort
      choose a random pivot or randomly shuffle the input numbers.
    (4)Numerical approximation algorithms
    "Here the random element allows us to get approximate numerical results, often much faster than direct methods, and multiple runs will provide increasing approximation."
    Examples:
    (*) Calculation of integrals