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)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Coin Change | BFS Approach
- Frobenius coin problem
- Find the player who will win the Coin game
- 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
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.