Given two integers N and R. The task is to calculate the probability of getting exactly r heads in n successive tosses.
A fair coin has an equal probability of landing a head or a tail on each toss.
Input : N = 1, R = 1 Output : 0.500000 Input : N = 4, R = 3 Output : 0.250000
Probability of getting K heads in N coin tosses can be calculated using below formula:
Below is the implementation of the above approach:
Time Complexity: In this implementation, we have to calculate factorial based on the value n, so time complexity would be O(n)
Auxiliary Space: In this implementation, we are not using any extra space, so auxiliary space required is O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Probability of not getting two consecutive heads together in N tosses of coin
- Probability of getting at least K heads in N tosses of Coins
- Probability of getting two consecutive heads after choosing a random coin among two different types of coins
- Probability of getting more heads than tails when N biased coins are tossed
- Expected number of coin flips to get two heads in a row?
- Count of total Heads and Tails after N flips in a coin
- Make a fair coin from a biased coin
- Expected Number of Trials to get N Consecutive Heads
- Probability of getting a sum on throwing 2 Dices N times
- Probability of getting more value in third dice throw
- Probability of getting a perfect square when a random number is chosen in a given range
- Probability of getting all possible values on throwing N dices
- Coin Change | DP-7
- Frobenius coin problem
- Coin Change | BFS Approach
- Find the player who will win the Coin game
- Minimum moves taken to move coin of each cell to any one cell of Matrix
- Philaland Coin | TCS Mockvita 2020
- Count ways to distribute exactly one coin to each worker
- Generate integer from 1 to 7 with equal probability
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.