All courses › Discrete Mathematics

Discrete Mathematics: free practice, theory and problems

Computers are built on logic: true and false, and and or. Sets are how mathematics collects things. Both show up everywhere in programming, databases and digital circuits.

3 parts36 problems9 concepts explainedPractice examFree
Start practising for free →

Contents

  1. Logic and sets
  2. Combinatorics
  3. Graphs and modular arithmetic

1. Logic and sets

What is it about?

Computers are built on logic: true and false, and and or. Sets are how mathematics collects things. Both show up everywhere in programming, databases and digital circuits.

Concepts and formulas

¬(p∧q)≡¬p∨¬q,¬(p∨q)≡¬p∧¬q\neg(p \wedge q) \equiv \neg p \vee \neg q, \qquad \neg(p \vee q) \equiv \neg p \wedge \neg q
∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|

How to solve the problems

  1. Logic: make a truth table, or use De Morgan and the contrapositive.
  2. Counting with overlap: add and subtract what was counted twice.
  3. "Neither": total minus the union.

Example

40 students: 25 take maths, 18 take physics and 10 take both. How many take neither?

  1. ∣M∪P∣=25+18−10=33|M \cup P| = 25 + 18 - 10 = 33.
  2. Neither: 40−33=740 - 33 = 7.

Common mistakes

∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. If–then is only false for "true → false".

Concepts in this part

Practise logic and sets in the app →

2. Combinatorics

What is it about?

How many passwords exist? In how many ways can a team be chosen? Combinatorics is systematic counting. It is used in probability, security (how long does it take to guess a password?) and algorithms (how many cases must be checked?).

Concepts and formulas

P(n,k)=n!(n−k)!P(n, k) = \frac{n!}{(n-k)!}
(nk)=n!k! (n−k)!\binom{n}{k} = \frac{n!}{k!\,(n-k)!}

How to solve the problems

  1. Ask: does order matter? Can the same thing be chosen more than once?
  2. Order and repetition: nkn^k. Order without repetition: P(n,k)P(n,k). No order: (nk)\binom nk.

Example

8 runners compete for gold, silver and bronze. How many possible podiums are there?

  1. The order matters, and nobody can get two medals.
  2. P(8,3)=8⋅7⋅6=336P(8,3) = 8\cdot 7\cdot 6 = 336.

Common mistakes

Order? Yes: P(n, k) or nᵏ. No: n choose k.

Concepts in this part

Practise combinatorics in the app →

3. Graphs and modular arithmetic

What is it about?

A graph is nodes (points) connected by edges (lines). Road networks, computer networks, friends on social media and dependencies between program modules are all graphs. Modular arithmetic is "clock arithmetic" with remainders, used in hashing, encryption and check digits.

Concepts and formulas

∑degree=2⋅(number of edges)\sum \text{degree} = 2\cdot(\text{number of edges})

How to solve the problems

  1. Count edges via the degrees: add up and divide by 2.
  2. For trees and complete graphs: use the formulas.
  3. Shortest path: try all reasonable routes in small graphs, or follow Dijkstra.

Example

Edges: A–B (4), A–C (1), C–B (2), B–D (5), C–D (8). Shortest path from A to D?

  1. A–C–B costs 1+2=31 + 2 = 3, which is cheaper than A–B directly (4).
  2. Then B–D: 3+5=83 + 5 = 8. The alternative A–C–D costs 1+8=91 + 8 = 9.
  3. The shortest path is A–C–B–D with length 8.

Common mistakes

Degree sum = 2 · edges. Tree: n − 1 edges. Kₙ: n(n − 1)/2 edges.

Concepts in this part

Practise graphs and modular arithmetic in the app →

Example problems with solutions

Here are some of the problems in discrete Mathematics. In the app, calculation problems get new numbers every time, so you can practise until it sticks – and take a graded practice exam before the real one.

Logic and sets: When is the implication p→qp \rightarrow q false?

Answer: When pp is true and qq is false

The implication promises that qq follows when pp holds. That promise is only broken when pp happens and qq does not.

Combinatorics: You have 3 shirts and 4 pairs of trousers. How many outfits can you make?

Answer: 12

Multiplication principle: 3⋅4=123\cdot 4 = 12.

Graphs and modular arithmetic: A graph has 7 edges. What is the sum of the degrees of all the nodes?

Answer: 14

Each edge adds 2 to the degree sum: 2⋅7=142\cdot 7 = 14.

Logic and sets: ∣A∣=20|A| = 20, ∣B∣=15|B| = 15 and ∣A∩B∣=5|A \cap B| = 5. What is ∣A∪B∣|A \cup B|?

Answer: 30

∣A∪B∣=20+15−5=30|A \cup B| = 20 + 15 - 5 = 30.

Practise all the problems →

Matches these university courses

The content covers the syllabus found in engineering degrees, for example: