commit 850f95bd60e32d3ac71b67b8afc0af36566047c4
parent f69ab180fa0056bd4febad809f2f6669e2af01b5
Author: ling0x <ling0x@users.noreply.github.com>
Date: Tue, 4 Aug 2026 13:29:03 +0100
probability and combinatorics
Diffstat:
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/algorithms/combinatorics.txt b/algorithms/combinatorics.txt
@@ -0,0 +1,23 @@
+========================================================================
+Combinatorics
+========================================================================
+
+Binomial Coefficient
+
+( n r ) = n! / r! (n-r)!
+
+in a scientific calculator its nCr, i.e. n choose r
+
+A committee of 4 is chosen from 6 analysts and 5 actuaries. It must contain at least 2 actuaries. How many committees are possible?
+A: 185 B: 200 C: 215 D: 230 E: 245
+
+(5 2)(6 2) = 10 x 15 = 150
+this is nCr(5 2) nCr(6 2), i.e. choose 2 from 5, choose 2 from 6
+
+(5 3)(6 1) = 10 x 6 = 60
+
+(5 4)(6 0) = 5 x 1 = 5
+
+Calculating it fast by hand:
+
+e.g. nCr(11 4) is 11 x 10 x 9 x 8 / 4 x 3 x 2 x 1 = 7920 x 24 = 330
diff --git a/algorithms/probability.txt b/algorithms/probability.txt
@@ -0,0 +1,60 @@
+========================================================================
+Probability
+========================================================================
+
+Bayes Theoreom
+
+P(A∣B)= P(B∣A)⋅P(A) / P(B)
+
+Where:
+
+P(A|B) = Posterior probability (probability of A given B has occurred)
+P(B|A) = Likelihood (probability of B given A is true)
+P(A) = Prior probability (initial belief about A before seeing evidence)
+P(B) = Evidence (total probability of observing B)
+
+Bayes' theorem lets you reverse conditional probabilities. If you know the probability of observing some evidence given a hypothesis, you can calculate the probability that the hypothesis is true given that you've observed the evidence.
+
+Practical Example:
+
+Imagine you're testing for a rare disease:
+
+The disease affects 1% of the population: P(Disease) = 0.01
+The test correctly identifies the disease 99% of the time: P(Positive|Disease) = 0.99
+The test has a 5% false positive rate: P(Positive|No Disease) = 0.05
+
+If you test positive, what's the actual probability you have the disease?
+
+Using Bayes:
+
+𝑃(Disease|Positive) = 0.99 × 0.01 / (0.99 × 0.01) + (0.05 × 0.99)
+= 0.0099 / 0.0594 ≈ 16.7%
+
+Even with a positive test, there's only about a 17% chance you actually have the disease—because the disease is so rare that false positives are common relative to true positives.
+
+This is why Bayes' theorem is so powerful: it captures how evidence should change our confidence in a hypothesis, accounting for base rates and test accuracy.
+
+
+Question:
+
+A machine has 4 independent components, each of which fails during a shift with probability 0.05. What is the probability that at least one fails?
+A: 5% B: 18.5% C: 19.0% D: 20% E: 81.5%
+
+
+Probability of at least 1 failing:
+
+0. so the component has a success probability of 1 - 0.05 = 0.95
+1. calculate the probability of all components functioning successfully:
+0.95 x 0.95 x 0.95 x 0.95 = 0.815
+2. so 1 - 0.815 is 0.185 is the chance of at least 1 component fails
+
+Probability of at least 2 failing:
+
+"At least 2 fails" is that same bundle with one case removed — exactly 1. So:
+0.05 x 0.95 x 0.95 x 0.95 = 0.0429
+But there are four different components that could be the one that failed, and those are four separate outcomes, so add them up:
+4 × 0.0429 = 0.1715
+Then subtract:
+0.185 − 0.1715 = 0.0140, about 1.4%
+
+Same logic extends upward: to get "at least 3", you'd take 0.0140 and subtract P(exactly 2). Each step peels off one more case from the bundle.
+\ No newline at end of file