Class 12 Maths, Worked in Full Past papersGet updates
Chapter 1 · Relations and Functions

Example 12: Swapping neighbours on N\N is bijective

ExamplesTypes of functions · Section 1.3
The question

Show that f:N→Nf : \N \to \N⁠, given by f(x)={x+1,if x is odd,x−1,if x is evenf(x) = \begin{cases} x + 1, & \text{if } x \text{ is odd,} \\ x - 1, & \text{if } x \text{ is even} \end{cases} is both one-one and onto.

Exam answer

One-one: Let f(x1)=f(x2)f(x_1) = f(x_2)⁠.

If x1x_1 is odd and x2x_2 is even, then x1+1=x2−1x_1 + 1 = x_2 - 1⁠, so x2−x1=2x_2 - x_1 = 2⁠. This is impossible, since even minus odd is odd. In the same way, x1x_1 even and x2x_2 odd is impossible.

If both are odd, x1+1=x2+1⇒x1=x2x_1 + 1 = x_2 + 1 \Rightarrow x_1 = x_2⁠. If both are even, x1−1=x2−1⇒x1=x2x_1 - 1 = x_2 - 1 \Rightarrow x_1 = x_2⁠. Thus ff is one-one.

Onto: Let y∈Ny \in \N⁠. If y=2r+1y = 2r + 1 is odd (r≥0)(r \ge 0)⁠, then 2r+22r + 2 is even and f(2r+2)=(2r+2)−1=yf(2r + 2) = (2r + 2) - 1 = y⁠. If y=2ry = 2r is even (r≥1)(r \ge 1)⁠, then 2r−12r - 1 is odd and f(2r−1)=(2r−1)+1=yf(2r - 1) = (2r - 1) + 1 = y⁠. Thus ff is onto.

Hence ff is both one-one and onto.

Want the reason behind every step, the basics and the checks?

The one idea this problem is built on

Work out a few values: f(1)=2f(1) = 2⁠, f(2)=1f(2) = 1⁠, f(3)=4f(3) = 4⁠, f(4)=3f(4) = 3⁠, and so on. The function swaps each odd number with the even number just after it. Odd inputs go to even outputs and even inputs go to odd outputs, so an odd input and an even input can never collide; and inside each parity the rule is a plain shift, which never repeats. Every output is the partner of exactly one input, so ff is one-one and onto. Doing ff twice puts every number back where it started.

Given, to show, and the plan
Given
A two-piece rule on N={1,2,3,… }\N = \{1, 2, 3, \dots\}⁠: add 1 to odd numbers, subtract 1 from even numbers.
To show
(a) ff is one-one. (b) ff is onto.
Plan
(1) Check ff maps N\N into N\N⁠, and note which parity each piece produces. (2) One-one: assume f(x1)=f(x2)f(x_1) = f(x_2) and go through all four parity combinations of x1,x2x_1, x_2⁠. (3) Onto: for an arbitrary yy⁠, split into yy odd and yy even and construct a preimage. (4) Conclude.

Basics you need

1Odd and even

Every natural number is odd or even, never both. Even numbers are 2r2r (r∈Nr \in \N⁠); odd numbers are 2r+12r + 1 (r=0,1,2,…r = 0, 1, 2, \dots⁠). Odd ±1\pm 1 is even, even ±1\pm 1 is odd, and an even number minus an odd number is odd. Basics: integers, even and odd

2Piecewise functions

To evaluate f(x)f(x)⁠, first decide which piece xx belongs to (here: odd or even), then use only that formula. Basics: what a function is

3One-one and onto

One-one: f(x1)=f(x2)⇒x1=x2f(x_1) = f(x_2) \Rightarrow x_1 = x_2⁠. Onto: every yy in the codomain is f(x)f(x) for some xx in the domain. Basics: one-one and onto

4Proof by cases

When a claim is about arbitrary x1,x2x_1, x_2⁠, and each can be odd or even, there are four combinations. Proving the claim in all four proves it outright. Basics: proving and disproving

Solution

  1. Check the outputs lie in N\N⁠, and note their parity

    • If xx is odd, f(x)=x+1≥2f(x) = x + 1 \ge 2 is a natural number, and it is even.
    • If xx is even, then x≥2x \ge 2⁠, so f(x)=x−1≥1f(x) = x - 1 \ge 1 is a natural number, and it is odd.
    xx12345678
    parityoddevenoddevenoddevenoddeven
    f(x)f(x)21436587
    inputs x (domain N)outputs f(x) (codomain N); exactly one arrow into each1122334455667788……
    Each neighbouring pair 2r−1,2r2r-1, 2r swaps places, shown in matching colours. Every output receives exactly one arrow: ff is one-one and onto.
    The check x−1≥1x - 1 \ge 1 matters: subtracting 1 from a natural number can give 0∉N0 \notin \N⁠, but only when x=1x = 1⁠, and 1 is odd, so it uses the other piece. The parity observation (odd goes to even, even goes to odd) is the key to the one-one proof in the next step.
    The smallest even natural number is 2, so for even xx we have x−1≥1x - 1 \ge 1⁠.
  2. One-one, mixed case: odd x1x_1⁠, even x2x_2 is impossible

    Suppose f(x1)=f(x2)f(x_1) = f(x_2)⁠. First suppose x1x_1 is odd and x2x_2 is even. Then the equation reads

    x1+1=x2−1,that isx2−x1=2.\begin{aligned} x_1 + 1 &= x_2 - 1, \\ \text{that is}\quad x_2 - x_1 &= 2. \end{aligned}

    But x2−x1x_2 - x_1 is an even number minus an odd number, which is odd, and 2 is even. An odd number cannot equal 2. So this case cannot happen. The case "x1x_1 even, x2x_2 odd" is ruled out the same way: it gives x1−1=x2+1x_1 - 1 = x_2 + 1⁠, so x1−x2=2x_1 - x_2 = 2⁠, with x1−x2x_1 - x_2 again even minus odd, hence odd.

    The book says only that x2−x1=2x_2 - x_1 = 2 "is impossible"; the reason is parity. A second way to see it: by Step 1, f(x1)f(x_1) is even and f(x2)f(x_2) is odd, and an even number cannot equal an odd number. Either way, when f(x1)=f(x2)f(x_1) = f(x_2)⁠, the inputs x1,x2x_1, x_2 must have the same parity.
    Even minus odd is odd: if x2=2ax_2 = 2a and x1=2b+1x_1 = 2b + 1⁠, then x2−x1=2(a−b−1)+1x_2 - x_1 = 2(a - b - 1) + 1⁠, which is odd.
  3. One-one, same-parity cases

    Now the inputs have the same parity, so the same formula applies to both.

    • Both odd: f(x1)=f(x2)f(x_1) = f(x_2) reads x1+1=x2+1x_1 + 1 = x_2 + 1⁠, so x1=x2x_1 = x_2 (subtract 1 from both sides).
    • Both even: f(x1)=f(x2)f(x_1) = f(x_2) reads x1−1=x2−1x_1 - 1 = x_2 - 1⁠, so x1=x2x_1 = x_2 (add 1 to both sides).

    All four parity combinations are covered: the two mixed ones cannot occur, and the two same-parity ones force x1=x2x_1 = x_2⁠. Hence ff is one-one.

    Within one piece the function is just a shift (x↦x+1x \mapsto x + 1 or x↦x−1x \mapsto x - 1⁠), and a shift can be undone, so equal outputs give equal inputs. The danger in a piecewise function is a collision between pieces, which Step 2 excluded. Only after checking both kinds of case is the proof complete.
    Proof by cases: x1x_1 odd or even, x2x_2 odd or even, gives four cases that cover every pair. Basics: proving and disproving
  4. Onto: every odd yy and every even yy has a preimage

    Take an arbitrary y∈Ny \in \N⁠. It is odd or even.

    • yy odd, say y=2r+1y = 2r + 1 with r≥0r \ge 0⁠. Choose x=2r+2x = 2r + 2⁠. This is an even natural number, so the second piece applies: f(2r+2)=(2r+2)−1f(2r + 2) = (2r + 2) - 1⁠, which is 2r+1=y2r + 1 = y⁠. ✓
    • yy even, say y=2ry = 2r with r≥1r \ge 1⁠. Choose x=2r−1x = 2r - 1⁠. This is an odd natural number (it is at least 1), so the first piece applies: f(2r−1)=(2r−1)+1f(2r - 1) = (2r - 1) + 1⁠, which is 2r=y2r = y⁠. ✓

    Every y∈Ny \in \N is an image, so ff is onto.

    Because ff swaps neighbours, the preimage of yy is simply its partner: y+1y + 1 if yy is odd, y−1y - 1 if yy is even. For each candidate we checked three things: it is in N\N⁠, it has the parity that selects the formula we used, and the formula really gives yy⁠. The condition r≥1r \ge 1 for even yy guarantees 2r−1≥12r - 1 \ge 1⁠.
    For onto, take an arbitrary yy⁠, construct xx⁠, and verify both x∈x \in domain and f(x)=yf(x) = y⁠. Basics: one-one and onto
  5. Conclude: ff is a bijection, and its own inverse

    ff is one-one (Steps 2 and 3) and onto (Step 4), so ff is both one-one and onto (bijective).

    A bonus fact: applying ff twice returns every number to itself. If xx is odd, f(x)=x+1f(x) = x + 1 is even, so f(f(x))=(x+1)−1=xf(f(x)) = (x + 1) - 1 = x⁠. If xx is even, f(x)=x−1f(x) = x - 1 is odd, so f(f(x))=(x−1)+1=xf(f(x)) = (x - 1) + 1 = x⁠. So ff undoes itself, which is another way to see that it is a bijection.

    If f(f(x))=xf(f(x)) = x for every xx⁠, then f(x1)=f(x2)f(x_1) = f(x_2) gives x1=f(f(x1))=f(f(x2))=x2x_1 = f(f(x_1)) = f(f(x_2)) = x_2 (one-one), and every yy equals f(f(y))f(f(y))⁠, the image of f(y)f(y) (onto). This idea becomes the inverse function in Section 1.4.
Result

ff swaps each odd number 2r−12r - 1 with the next even number 2r2r⁠. It is one-one (odd and even inputs land on outputs of opposite parity, so they cannot collide, and within each parity ff is a shift) and onto (an odd 2r+12r+1 is f(2r+2)f(2r+2)⁠, an even 2r2r is f(2r−1)f(2r-1)⁠). So ff is a bijection, and f(f(x))=xf(f(x)) = x for all xx⁠.

Play this problem

Balloon Pop, in the chapter’s Games tab. Machine 3 is this function: every balloon is hit exactly once. Play Balloon Pop ↗

Check it with numbers

Apply ff to 1,2,…,1001, 2, \dots, 100⁠: the outputs 2,1,4,3,…,100,992, 1, 4, 3, \dots, 100, 99 are the numbers 11 to 100100⁠, each exactly once. For single values: y=37y = 37 is odd, 37=2⋅18+137 = 2\cdot 18 + 1⁠, so the preimage is 2⋅18+2=382\cdot 18 + 2 = 38⁠, and f(38)=37f(38) = 37⁠. ✓ y=50=2⋅25y = 50 = 2 \cdot 25 is even, so the preimage is 4949⁠, and f(49)=50f(49) = 50⁠. ✓

Common mistakes
  1. Checking only the same-parity cases. Each piece is one-one on its own, but that does not stop an odd input and an even input from sharing an output. The mixed cases must be ruled out (Step 2). Compare Exercise 1.2 Q9, where exactly such cross-piece collisions happen.
  2. Calling x2−x1=2x_2 - x_1 = 2 "impossible" without a reason. On its own, x2−x1=2x_2 - x_1 = 2 is perfectly possible (for example 5−3=25 - 3 = 2⁠). It is impossible here only because x2x_2 is even and x1x_1 is odd.
  3. Using the wrong formula for the preimage. The preimage of an odd yy is the even number y+1y + 1⁠, which is evaluated with x−1x - 1⁠, not x+1x + 1⁠.
What to take away
  1. For a piecewise function, prove one-one in two parts: no collisions between pieces, and no collisions within a piece.
  2. Parity is a quick way to rule out collisions: if the pieces produce outputs of different kinds, they cannot share an output.
  3. A function that is its own inverse (f(f(x))=xf(f(x)) = x⁠) is automatically a bijection.

Every fact used, and where it comes from

FactUsed inSource
Every natural number is exactly one of odd, evenSteps 1–4Definition of odd and even
Odd ±1\pm 1 is even; even ±1\pm 1 is odd; even − odd is oddSteps 1, 2Parity arithmetic
Definition of one-oneSteps 2, 3Definition 5, Section 1.3 (Lesson: types of functions)
Definition of ontoStep 4Definition 6, Section 1.3
Definition of bijectiveStep 5Definition 7, Section 1.3
f(f(x))=xf(f(x)) = x and inversesStep 5 remarkSection 1.4 (Lesson: invertible functions)
Found an error, or want more?

Tell us if something on this page is wrong or unclear, or if you would like a fuller explanation, another method or a new feature. Send feedback on this problem →