Math for coding interviews/Probability - expected outcomes
Probability for Coding Interviews, Explained Simply
Probability is just a fraction between 0 and 1. Something that never happens has probability 0. Something that always happens has probability 1. A coin flip landing heads has probability 0.5 (50%). The more times you repeat something, the closer your results get to the expected fraction.
See it for yourself
A bar that fills from left to right. The filled portion represents how often an outcome occurs across all trials. Flip a coin 100 times and the bar gets close to 50/50. Flip 10,000 times and it is almost exactly 50/50.
Probability - expected outcomes
Probability is just a fraction between 0 and 1. Something that never happens has probability 0. Something that always happens has probability 1. A coin flip landing heads has probability 0.5 (50%). The more times you repeat something, the closer your results get to the expected fraction.
Think of it this way: If you roll a six-sided die 6,000 times, you would expect each number to show up roughly 1,000 times. The more rolls, the more even the distribution.
For algorithms: Randomized algorithms (like quicksort with random pivot) use probability to guarantee good average performance even when any single run might be unlucky.
Real-world analogy
If you roll a six-sided die 6,000 times, you would expect each number to show up roughly 1,000 times. The more rolls, the more even the distribution.
Why it matters in interviews
Randomized algorithms (like quicksort with random pivot) use probability to guarantee good average performance even when any single run might be unlucky.