Courses / Computer Science I
Discrete Mathematics

Functions

A function f: A B assigns to each element of the domain A exactly one element of the codomain B.

Computer Science I 218 words Free to read

Mapping Rules

A function f:ABf: A \to B assigns to each element of the domain AA exactly one element of the codomain BB. The image (range) is the set of outputs actually hit.

Three core properties describe how functions map sets:

PropertyDefinitionKey Formula / Rule
InjectiveOne-to-one, no two inputs collidef(a)=f(a)    a=af(a) = f(a') \implies a = a'
SurjectiveOnto, codomain is fully coveredImage=B\text{Image} = B
BijectiveBoth injective and surjectivePerfect pairing between AA and BB

Bijections are invertible, possessing an inverse f1f^{-1} that undoes the mapping. They define set cardinality, letting us compare even infinite sets by checking if a bijection exists between them.

Composition and Pitfalls

Functions compose: given f:ABf: A \to B and g:BCg: B \to C, the composition gf:ACg \circ f: A \to C applies ff first, then gg. Programs are built from composed functions transforming data step-by-step.

Common Pitfall: Mixing up injective and surjective, or misreading composition order. Injective means inputs do not collide; surjective means the codomain is fully covered. Always remember that gfg \circ f means apply ff then gg—the right-hand function runs first, which looks backwards until you practice it.
Functions

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

9practice questions
2interactive scenes

Discrete Mathematics