LearnViz CompSci
Home / Learn / Theory & Discrete Math / Functions and Relations

Beginner Topic 4 of 51 Theory & Discrete Math

Functions and Relations

Mappings and pairings between sets.

How it works

A relation between sets A and B is a subset of their Cartesian product, pairing elements that are related. Properties include reflexive, symmetric, antisymmetric and transitive; equivalence relations partition a set into classes and partial orders define hierarchies. A function is a relation assigning each input exactly one output, and can be injective, one-to-one, surjective, onto, or bijective, both, which means it has an inverse.

Step-by-step walkthrough

  1. A relation is any set of pairs between two sets.
  2. A function gives each input exactly one output.
  3. One-to-one: no two inputs share an output.
  4. Onto: every codomain element is hit.
  5. A function that is both has an inverse.

Where it is used

Database tables model relations, hash functions and mappings model functions, equivalence relations define grouping, and orders define sorting and dependency graphs.

Common pitfall

Confusing a function with a formula ignores domain and codomain: changing them changes injectivity and surjectivity. Multi-valued mappings are not functions. Checking transitivity or antisymmetry by only a few examples can miss counterexamples. Composition order is easy to reverse. State the domain and codomain and test properties with definitions.

Where it fits in the course

Functions and Relations is topic 4 of 51 in Theory & Discrete Math, rated Beginner. It follows Sets and Set Operations. The next topic is Mathematical Induction.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Theory & Discrete Math quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Functions and Relations?
Mappings and pairings between sets. It belongs to Theory & Discrete Math and is a beginner-level topic.
Where do people use Functions and Relations?
Database tables model relations, hash functions and mappings model functions, equivalence relations define grouping, and orders define sorting and dependency graphs.
What is the most common mistake with Functions and Relations?
Confusing a function with a formula ignores domain and codomain: changing them changes injectivity and surjectivity.
What should I learn before this topic?
Start with Sets and Set Operations, the topic just before it in Theory & Discrete Math.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Theory & Discrete Math quiz.
Is Functions and Relations hard to learn?
It is a Beginner topic, so it works as an entry point. If the terms are new, read the explanation twice and try the visualizer before the quiz.
How long does it take to learn Functions and Relations?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Functions and Relations?
Sets and Set Operations, Mathematical Induction, Predicate Logic are closely connected. The full list is in the related topics section of this page.
What should I study after Functions and Relations?
Continue with Mathematical Induction, the next topic in Theory & Discrete Math.

Related topics