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
- Expected number of coin flips to get two heads in a row?
- Count of total Heads and Tails after N flips in a coin
- Probability of getting more heads than tails when N biased coins are tossed
- Make a fair coin from a biased coin
- Expected Number of Trials to get N Consecutive Heads
- Coin Change | DP-7
- Frobenius coin problem
- Coin Change | BFS Approach
- Find the player who will win the Coin game
- Philaland Coin | TCS Mockvita 2020
- Probability of rain on N+1th day
- Minimum moves taken to move coin of each cell to any one cell of Matrix
- Probability of getting more value in third dice throw
- Probability of a key K present in array
- Probability that two persons will meet
- Maximizing Probability of one type from N containers
- 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 firstname.lastname@example.org. 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.