Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

3 Ants and Triangle- Interview Puzzle

1.Three ants are sitting at the three corners of an equilateral triangle. Each ant starts randomly picks a direction and starts to move along the edge of the triangle. What is the probability that none of the ants collide?


Solution:-

So let’s think this through. The ants can only avoid a collision if they all decide to move in the same direction (either clockwise or anti-clockwise). If the ants do not pick the same direction, there will definitely be a collision. Each ant has the option to either move clockwise or anti-clockwise. There is a one in two chance that an ant decides to pick a particular direction. Using simple probability calculations, we can determine the probability of no collision.

P(No collision) = P(All ants go in a clockwise direction) + P( All ants go in an anti-clockwise direction) = 0.5 * 0.5 * 0.5 + 0.5 * 0.5 * 0.5 = 0.25


A simple way to solve.


  1. Each ant has 2 possibilities of moving in a direction.. clockwise or anti-clockwise. Now as there are 3 ants .. we have 8 total possibilities of the ants moving in a direction.

Now out of 8 we can have only 2 possibilities where they will not collide.
i.e if all the ants travel clockwise or all the ants travel anti-clockwise.
so the probability is 2/8 = 1/4 = 0.25

  • P(#collision)=  #of way when there is no collision/ total number of way ants can move

= 2/2^3
= 1/4




No comments:

Post a Comment