Implement a fair coin given an unfair coin
Given an unfair coin, where probability of heads coming up is P and tails is (1-P). Implement a fair coin from the given unfair coin.
Algorithm:
Let us define an event.
An event is defined as flipping the unfair coin twice.
Let us observe probability of all possible events.
Event 1: Probability of heads coming up in both is P*P
Event 2: Probability of tails coming up in both is (1-P)* (1-P)
Event 3: Probability of heads coming up in first and tails in second is P*(1-P)
Event 4: Probability of tails coming up in first and heads in second is (1-P)*P
If you observe carefully, you would notice that events 3rd and 4th occur with equal probability of P*(1-P).
So, if we ignore events 1st and 2nd of getting both heads or tails, since they have different probabilities, we are left with events 3rd and 4th which occur with equal probability.
So, Keep flipping the unfair coin two at a time, until they come up with different values, then return value of first flip of the coin (out of the two flips).
We have used probability theory formulas here without going into the details of proofs and theory. Curious readers can check out wiki links on these topics.
Sometimes this problem is also asked as:
Make a fair coin from a biased coin
Simulate a fair coin toss with a biased coin
How to make a biased coin unbiased
Biased coin to fair coin
Getting a Fair Toss From a Biased Coin
Write a function which returns true and false with equal probability
Code and Algorithm Visualization:
Coming soon on http://www.ideserve.co.in. Stay Tuned!
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Implement a fair coin given an unfair coin канала IDeserve
Algorithm:
Let us define an event.
An event is defined as flipping the unfair coin twice.
Let us observe probability of all possible events.
Event 1: Probability of heads coming up in both is P*P
Event 2: Probability of tails coming up in both is (1-P)* (1-P)
Event 3: Probability of heads coming up in first and tails in second is P*(1-P)
Event 4: Probability of tails coming up in first and heads in second is (1-P)*P
If you observe carefully, you would notice that events 3rd and 4th occur with equal probability of P*(1-P).
So, if we ignore events 1st and 2nd of getting both heads or tails, since they have different probabilities, we are left with events 3rd and 4th which occur with equal probability.
So, Keep flipping the unfair coin two at a time, until they come up with different values, then return value of first flip of the coin (out of the two flips).
We have used probability theory formulas here without going into the details of proofs and theory. Curious readers can check out wiki links on these topics.
Sometimes this problem is also asked as:
Make a fair coin from a biased coin
Simulate a fair coin toss with a biased coin
How to make a biased coin unbiased
Biased coin to fair coin
Getting a Fair Toss From a Biased Coin
Write a function which returns true and false with equal probability
Code and Algorithm Visualization:
Coming soon on http://www.ideserve.co.in. Stay Tuned!
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Implement a fair coin given an unfair coin канала IDeserve
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Programming Interview Question: How to print all diagonal's sums for a given binary tree?Level Order TraversalReverse a Linked List - IterativeProgramming Interview Question: Searching a 2D Sorted MatrixBuying and selling stocksBinary SearchMinimum length subarray of an unsorted array sorting which results in complete sorted arrayFind an element in a sorted rotated array without finding pivot (minimum element)Maximum size square sub-matrix with all 1sBuilding Bridges Dynamic ProgrammingLeaders in an arrayFind intersection of two Linked Lists - O(A + B) Time Complexity and O(1) Space ComplexityCreate a balanced Binary Search Tree (BST) from a sorted arrayNext greater element in an arraySpiral level order traversal of a binary treeProgramming Interview Question: Recover Binary Search TreeDetect a loop in a linked listProgramming Interview Question: Find intersection of two Linked ListsFind an element in a sorted rotated arrayDemo of IDeserve web platform www.ideserve.co.in