// PROBABILITY · INTERMEDIATE

Probability Basics

Sample spaces, events, conditional probability, Bayes' theorem, and expected value — the foundation of probabilistic reasoning.

Intermediate·25 min·Probability
Reviewed by CodeTikki Academic Team

Prerequisites: Permutations & Combinations · Basic counting

// DICE DISTRIBUTION

Visualize dice probabilities

Adjust the number of dice and target sum to see the probability distribution update in real time.

2.8%
2
5.6%
3
8.3%
4
11.1%
5
13.9%
6
16.7%
7
13.9%
8
11.1%
9
8.3%
10
5.6%
11
2.8%
12

P(sum = 7) = 6 / 36 = 16.67%

// KEY FORMULAS

Core probability rules

Classical Probability

P(E) = |favorable| / |sample space|

For equally likely outcomes

Complement Rule

P(not E) = 1 - P(E)

The complement of an event

Addition Rule

P(A or B) = P(A) + P(B) - P(A and B)

Union of two events

Conditional Probability

P(A | B) = P(A and B) / P(B)

Probability of A given B

Bayes' Theorem

P(A|B) = P(B|A) · P(A) / P(B)

Update beliefs with evidence

Binomial Distribution

P(k|n) = C(n,k) · pᵏ · (1-p)ⁿ⁻ᵏ

k successes in n trials

// ALGORITHM

Computing binomial probabilities mod p

Precompute factorials and modular inverses to evaluate C(n, k) mod p in O(1) per query.

// PSEUDOCODE · Binomial Coefficient mod p
C(n, k) mod p using precomputed factorials and Fermat inverses
n = 1000, k = 500, p = 1e9+7
1function binomialModP(n, k, p):
2 if k < 0 or k > n: return 0
3 // Precompute: fact[i] = i! mod p
4 // invFact[i] = (i!)^(-1) mod p (via Fermat)
5 num = fact[n]
6 den = (invFact[k] * invFact[n-k]) mod p
7 return (num * den) mod p

Press PLAY to step through the algorithm line by line.

0 / 6

// INTERACTIVE GAME

Probability Predictor

Given a probability question, pick the correct percentage. Test your intuition!

Probability Predictor

Estimate the probability as a percentage

You'll be shown a probability question. Pick the correct percentage!

// FLOWCHART

Solving probability problems

// FLOWCHART · Solving Probability Problems
From sample space to verified answer
YesNoYesNoStartDefine samplespace SIdentify eventE ⊆ SEventsindependent?Use product ruleP(A)·P(B)P(E) = |E|/|S|or BayesCompute result0 ≤ P ≤ 1and sum = 1?DoneRecheckassumptions

Press PLAY to trace the algorithm through the flowchart.

0 / 9

// TUTORIAL QUIZZES

Test your mastery

From basic probability to Bayes' theorem and binomial distributions.

// PRACTICE & ASSESS

Test your understanding

Now that you've learned the concept, put it into practice. Solve coding problems and take quizzes to reinforce what you've learned.

// REFERENCES

Sources & further reading

  1. [1]
    A First Course in ProbabilitySheldon Ross — classic probability textbook
  2. [2]
    Probability and StatisticsMorris H. DeGroot & Mark J. Schervish — comprehensive reference
  3. [3]
    Introduction to ProbabilityJoseph K. Blitzstein & Jessica Hwang — with applications
  4. [4]
    The Art of Computer Programming, Vol. 2Donald E. Knuth — random numbers and probability

// READY?

Encode sequences with generating functions

Next up: Generating Functions — transform counting problems into algebraic manipulations of power series.