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.

In short

¬(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|

Propositional logic in practice

A proposition is a statement that is either true or false. With connectives we build compound statements: not (¬\neg), and (∧\wedge), or (∨\vee), if–then (→\to) and if and only if (↔\leftrightarrow). A truth table with 2n2^n rows for nn variables always gives the answer.

Quantifiers

"For all" (∀\forall) and "there exists" (∃\exists). Negation swaps the quantifier: ¬∀x P(x)≡∃x ¬P(x)\neg \forall x\, P(x) \equiv \exists x\, \neg P(x). To disprove "all primes are odd" a single counterexample suffices: 2.

Sets

A set is a collection of distinct elements. Key operations are union A∪BA \cup B, intersection A∩BA \cap B, difference A∖BA \setminus B and complement AcA^c. Venn diagrams make them concrete. Inclusion–exclusion: ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B|. The power set of a set with nn elements has 2n2^n subsets – each element is either in or out. The Cartesian product A×BA \times B is all ordered pairs, with ∣A∣⋅∣B∣|A| \cdot |B| elements.

Why engineers need this

Logic underlies digital circuits (AND, OR, NOT gates), database queries (WHERE conditions) and program verification. Sets are used in databases (relations are sets of rows), probability (events are sets of outcomes) and algorithms.

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?).

In short

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)!}

Four basic situations

Most combinatorics comes down to two questions: does order matter, and can the same item be chosen more than once?

The sum and product rules

When choices happen one after another, multiply. When counting separate cases that do not overlap, add. "Passwords with 4 or 5 digits" gives 104+10510^4 + 10^5. If the cases overlap, subtract what is counted twice (inclusion–exclusion).

Counting the complement

It is often easier to count what you don't want. "At least one" → all minus "none". The number of bit strings of length 8 with at least one 1 is 28−1=2552^8 - 1 = 255.

Binomial coefficients and Pascal's triangle

(nk)\binom{n}{k} are the numbers in Pascal's triangle, where each number is the sum of the two above: (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}. The binomial theorem (a+b)n=∑k(nk)an−kbk(a+b)^n = \sum_k \binom{n}{k} a^{n-k} b^k explains the name. The symmetry (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k} says that choosing who is in is the same as choosing who is out.

The pigeonhole principle

Put n+1n+1 letters into nn holes and at least one hole gets two. Simple but powerful: among 367 people at least two share a birthday, and any hash function mapping many inputs to fewer values must have collisions.

Applications

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.

In short

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

Graphs

A graph consists of vertices (nodes) and edges between them. It can be directed (one-way streets, web links) or undirected, and edges can have weights (distance, cost, capacity).

Key algorithms

Modular arithmetic

a mod na \bmod n is the remainder when aa is divided by nn. We write a≡b(modn)a \equiv b \pmod n when aa and bb leave the same remainder. Clock arithmetic: 10 hours after 20:00 is 30 mod 24=630 \bmod 24 = 6.

Applications

Modular arithmetic is everywhere in computing: hash tables (index = key mod table size), check digits (national ID numbers, ISBN, bank account numbers with mod 11), circular buffers, random numbers and cryptography – RSA relies on it being easy to compute powers modulo a large number but very hard to factor it.

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 practice exam with an indicative grade as you prepare for the exam.

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 follows the syllabus found in, for example: