The University of Hong Kong · FACULTY OF COMPUTER SCIENCE

COMP2121 Chap.7 Probability and Conditional Probability

- one subject, every graph, every model, every mark
6 Chapters5-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 7 of 11 · COMP2121

Probability and Conditional Probability

Sample spaces and equal likelihood

Probability starts with a sample space and events as its subsets. When outcomes are equally likely, a probability is a ratio of counts, but the outcomes must be chosen so that equal likelihood really holds, as ordered dice pairs do and unordered ones do not.

Conditioning, independence and Bayes

Conditioning on an event shrinks the sample space to that event.

Independence is tested numerically by comparing a conditional probability with the unconditional one. The law of total probability and Bayes' theorem reverse a condition, which a tree diagram makes concrete.

Writing a conditional answer clearly

Name each event with a letter and write the given information as conditional probabilities before any arithmetic.

The course solutions make the condition explicit, writing the probability of E given F rather than an unlabelled fraction, and check that the conditioning event has positive probability.

When a question gives the probability of a result given a cause and asks for the cause given the result, the answer needs Bayes' theorem and a total probability for the denominator.

Independence is a calculation

Two events are independent when the probability of both equals the product of their probabilities. Intuition is unreliable here.

With two dice, the event that the first die is even and the event that the sum is seven are independent, even though both involve the first die, while the events that the sum is eight and that both dice are even are not. Mutual independence of three events needs every pair and the triple to satisfy the product rule.

In this chapter

What this chapter covers

  • 01

    Sample spaces and events

  • 02

    Equally likely outcomes

  • 03

    Conditional probability

  • 04

    Independence

  • 05

    Total probability

  • 06

    Bayes' theorem

Worked example · free

Reverse a test result with a probability tree

Q [6 marks]. This practice weighting was set for revision and is not an official University marking scheme. A condition affects 1% of a population. A test detects it 95% of the time and gives a false positive 10% of the time. Find the probability that a person with a positive result has the condition.
A tree for a test with one per cent prevalence, 95 per cent sensitivity and a 10 per cent false positive rate.A tree for a test with one per cent prevalence, 95 per cent sensitivity and a 10 per cent false positive rate. First branches split by condition and second branches by test result; each leaf shows the product along its path, and the four leaves sum to one.disease 0.01+ 0.950.0095− 0.050.0005healthy 0.99+ 0.100.0990− 0.900.8910
A tree for a test with one per cent prevalence, 95 per cent sensitivity and a 10 per cent false positive rate. First branches split by condition and second branches by test result; each leaf shows the product along its path, and the four leaves sum to one.
  • 2Draw the tree with the condition first and the result second.
  • 2Multiply along branches and add the positive leaves.
  • 2Divide to get the posterior.
The positive leaves are 0.01 times 0.95, which is 0.0095, and 0.99 times 0.10, which is 0.099. Their sum, 0.1085, is the probability of a positive result. The posterior is 0.0095 divided by 0.1085, about 0.088, so fewer than one positive in eleven comes from someone with the condition.
Sia tip — Write the condition after the bar in words before calculating.
Glossary

Key terms

Sample space
The set of all possible outcomes of an experiment.
Conditional probability
The probability of an event given that another event of positive probability has occurred.
Independent events
Events for which the probability of their intersection equals the product of their probabilities.
FAQ

Probability and Conditional Probability FAQ

Why can I not count unordered dice outcomes?

Unordered outcomes are not equally likely: a double arises in one way and a mixed pair in two. Counting them as equal gives wrong answers, so count ordered pairs instead.

How do I test whether two events are independent?

Compute both sides of the product rule, or compare the conditional probability with the unconditional one. Intuition is unreliable; two events in the same game can be independent while two others are not.

Why is the posterior so small for a rare condition?

False positives from the large unaffected group outnumber true positives from the small affected group. The base rate enters through the denominator of Bayes' theorem. Drawing the tree with whole-number counts makes this effect easy to see.

Is pairwise independence enough for three events?

No. Three events can each be independent of each other in pairs while the probability of all three is not the product of the three probabilities. Mutual independence needs the product rule for every pair and for the triple.

What is the law of total probability?

If events F1 to Fn split the sample space into disjoint parts with positive probability, then the probability of E is the sum of the probability of E given each part times the probability of that part. It supplies the denominator in Bayes' theorem and is exactly the sum over the branches of a tree.

Study strategy

Exam move

For each problem, write the sample space and check equal likelihood before counting. Name events with letters and record given information as conditional probabilities. Practise drawing trees for two-stage experiments, confirm the leaves sum to one, and keep one example where the two directions of a condition give different numbers.

Keep a short list of problems where intuition about independence failed, and recompute each one with the product rule. Rewrite each answer as a sentence in plain language, which exposes a condition placed on the wrong side of the bar.

Working through Probability and Conditional Probability in COMP2121? Sia is AskSia’s AI Computer Science tutor — ask any COMP2121 Probability and Conditional Probability question and get a clear, step-by-step explanation grounded in how COMP2121 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 52 of your subjects at The University of Hong Kong, plus 1,000+ more Bibles across the AskSia library.
Sia - your COMP2121 tutor, unlimited, worked the way the exam marks it
The full 5-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works