Lessons / Probability / Practice

Learn this topic first

Skip to the questions ↓

Read this, then start. Tap a topic to open or close it.

Probability
Exam weightage: HighAbout 1-2 questions per placement paper. Seen most in TCS NQT, Infosys, Capgemini. All topics

If I toss a coin, will it be heads? Nobody knows. But everyone in this room would bet it is heads about half the time. Probability is simply that 'about half', written as a number.

What probability means

Probability is a number between 0 and 1 that says how likely something is. 0 means it cannot happen. 1 means it is certain. 1/2 means it happens half the time.

To find it, count. Probability of an event = (number of ways the event can happen) / (total number of possible outcomes). This only works when every outcome is equally likely: a fair coin, a fair die, a well-shuffled deck, a ball drawn without looking.

P(E) = favourable outcomes / total outcomes
Count what you want, count everything, divide.
0 ≤ P(E) ≤ 1
If you get more than 1 or a negative number, you have made a counting mistake.
P(not E) = 1 - P(E)
Something either happens or it does not.

Coins

One coin has 2 outcomes: H and T. Two coins have 2 × 2 = 4: HH, HT, TH, TT. Three coins have 2 × 2 × 2 = 8. In general n coins give 2n outcomes.

HT and TH are DIFFERENT outcomes. Think of the coins as a 1-rupee and a 2-rupee coin: 'first heads, second tails' is not the same as 'first tails, second heads'. If you merge them you get 3 outcomes that are not equally likely, and every answer comes out wrong.

n coins: 2n outcomes
1 coin 2, 2 coins 4, 3 coins 8, 4 coins 16.
P(exactly k heads) = nCk / 2n
Choose which k coins are heads.
P(at least one head) = 1 - 1/2n
The only way to fail is all tails.

Dice

A die has 6 faces, so one die gives 6 outcomes. Two dice give 6 × 6 = 36 outcomes, written as pairs: (1,1), (1,2) ... (6,6). Draw the 6 × 6 grid below once in your notebook. Every two-dice question is just shading the right boxes and counting them.

Sums follow a pattern. Sum 2 has 1 way, sum 3 has 2 ways, and so on up to sum 7, which has 6 ways. Then it falls: sum 8 has 5 ways, sum 12 has 1. So the number of ways for a sum s is (s - 1) when s is 7 or less, and (13 - s) when s is more than 7.

Cards

A pack has 52 cards in 4 suits: spades and clubs (black), hearts and diamonds (red). Each suit has 13 cards: A, 2, 3 ... 10, J, Q, K.

So there are 4 of every rank (4 aces, 4 kings), 13 of every suit, and 26 of each colour. Face cards (also called court cards) are J, Q and K: 3 per suit, 12 in total.

Balls in a bag: with and without replacement

'With replacement' means the ball goes back before the next draw, so every draw looks exactly like the first. 'Without replacement' means it stays out, so the second draw has one ball fewer, and one fewer of whatever colour came out.

If balls are drawn 'together' or 'at the same time', that is the same as without replacement, and combinations are the fastest way to count.

At least one: use the complement

'At least one' means one, or two, or three, or more. Counting all of those cases separately is slow and easy to get wrong.

The opposite of 'at least one' is 'none'. And 'none' is usually one simple case. So P(at least one) = 1 - P(none).

P(at least one) = 1 - P(none)
Works for coins, dice, people, machines, shots at a target.
P(none) for independent events = (1 - p1)(1 - p2)(1 - p3)...
Each person fails independently, so multiply the failure chances.

OR: the addition rule

P(A or B) means the chance that A happens, or B happens, or both. If you just add P(A) + P(B), the outcomes where both happen get counted twice. So subtract them once: P(A or B) = P(A) + P(B) - P(A and B).

If A and B can never happen together (mutually exclusive), the overlap is empty and you simply add. Example: one die shows 2 or shows 5. It cannot show both, so 1/6 + 1/6 = 1/3.

P(A or B) = P(A) + P(B) - P(A and B)
Add, then remove the double-counted overlap.
Mutually exclusive: P(A or B) = P(A) + P(B)
No overlap, nothing to remove.

AND: the multiplication rule

P(A and B) is the chance that both happen. If the two events do not affect each other (independent), multiply: P(A) × P(B). Coins, dice and draws WITH replacement are independent.

If the first event changes the second (dependent), multiply by the second probability AFTER the first has happened. Draws WITHOUT replacement are dependent.

Conditional probability: 'given that'

Sometimes the question tells you something has already happened: 'given that the sum is even', 'if it is known that one child is a boy'. That information shrinks the sample space. Throw away every outcome that does not fit, and count only among the ones left.

As a formula: P(A given B) = P(A and B) / P(B). But the shrink-and-count method is easier to understand and gives the same answer.

P(A given B) = P(A and B) / P(B)
Among the outcomes where B happened, what fraction also have A?

Odds, and how questions are worded

Odds are another way of saying probability. 'Odds in favour of E are 3 : 5' means for every 3 ways E happens there are 5 ways it does not. So there are 8 equally likely ways in total and P(E) = 3/8. 'Odds against E are 3 : 5' means P(E) = 5/8.

The table below turns the usual phrases into the rule you need.

Worked exampleA bag has 3 red, 4 green and 5 blue balls. One ball is taken out without looking. What is the probability it is green?
  1. Total outcomes = 3 + 4 + 5 = 12 balls.Each ball is equally likely to be picked, so each ball is one outcome.
  2. Favourable outcomes = 4 green balls.These are the outcomes that make our event (green) happen.
  3. P(green) = 4/12 = 1/3.
Treating HT and TH as the same outcome, so two coins seem to have 3 outcomes.
Label the coins (first, second). Two coins always have 4 outcomes.
Adding success chances: 1/2 + 1/3 = 5/6 for 'A or B solves it'.
Use 1 - P(both fail) = 1 - 1/2 × 2/3 = 2/3.
Keeping the bag the same size on the second draw without replacement.
Take one ball out of the total and out of its colour: 5/8 then 4/7.