Complicated comparing sets Consider the open interval $(0, 1)$ and the closed interval $[0, 1]$. We claim that $[0, 1] ≈ (0, 1)$.
We deduced the equipotence $[0, 1] ≈ (0, 1)$ by invoking the Schr¨oder–Bernstein theorem, but we didn’t actually construct a bijection $[0, 1] → (0, 1).$

(a) Verify that the function $h$ given by the following scheme is such a bijection: $$0\overset{h}{\longmapsto}\frac12\qquad\qquad\qquad\qquad\qquad\qquad\quad\,{}\\\frac1n\longmapsto\frac1{n+2}\qquad\text{for each integer }n\ge 1\\x\longmapsto x\qquad\qquad\qquad\qquad\quad\;\text{otherwise}$$


(b) The function $h$ in part (a) acts on $[0, 1]$ in a way that resembles the strategy of the hotel manager in the text below. How?

Now imagine that there is a hotel with infinitely many rooms along an unending corridor: a first room, a second room, and so on. Imagine further that there is a person occupying each room; so we can reasonably say that there are exactly as many guests as there are rooms. You arrive at the hotel seeking a room, and the manager tells you, “At the moment the rooms are all occupied, but we always have room for one more.” Whereupon she speaks into an intercom connected to all the rooms, saying, “At the sound of the bell, each guest should step out into the corridor and move into the next room in line.” This clears out the first room, and you have a place to stay. Notice that although you thought you had enlarged the collection of guests by your presence, there are still as many hotel rooms as there are guests.


My work is below:

We are given function $h$ $$h(x)=\begin{cases}\cfrac1{n+2} & \text{for }x=\cfrac1n,n\ge 1\\\cfrac12 & \text{for }x=0\\x & \text{otherwise}\end{cases}$$
We know that a function from $A$ (the domain) to $B$ (the range) is both one-to-one and onto when no element of $B$ is the image of more than one element of $A,$ and all elements in $B$ are used.
Functions that are both one-to-one and onto are referred to as bijective. Here we can say that $h(x)$ is an identity function as $x,$ in the form of $\frac1n$ and $x\ne0.$
We know that an identity function is bijective.
For $x\ne\frac1n$ and $x\ne 0,$ $h(x)$ is bijective.
Let us consider $x_1=\frac{1}{n_1},x_2=\frac{1}{n_2}$ and assume that $h(x_1)=h(x_2),$ so $h\left(\frac{1}{n_1}\right)=h\left(\frac{1}{n_2}\right).$ Then, $$\frac{1}{n_1+2}=\frac{1}{n_2+2}\iff n_1+2=n_2+2$$
Therefore, $n_1=n_2,$ thus $x_1=x_2$ which proves that $h(x)$ is one-to-one.
For $n\ge 1,$ $\frac{1}{n+2}\ne\frac{1}{2}$
Thus, only $x=0$ maps to $\frac12.$
Let us check identity function for the numbers $y=\frac1n,n>2.$
If we have $y=\frac1n,$ then there exists an element $x$ such that $\frac1n=h\left(\frac{1}{n-2}\right),$ $x=\frac1{n-2}$
Therefore, $h(x)$ is onto, so we conclude that $h(x)$ is bijective.

This question is driving me nuts. Please give me some advice on how to answer it concisely. Thank you so much!

Here is how the  construction of that bijection mirrors the freeing of the first two rooms in Hilbert's Hotel.
The function $h$ matches the rational numbers
$$
0, 1/1, 1/2, 1/3, 1/4, 1/5, \ldots
$$
in order to the rational numbers
$$
1/2, 1/3, 1/4, 1/5, 1/6, 1/7, \ldots
$$
That says the inverse function $h^{-1}$ creates "rooms" for the extra guests $0$ and $1$ by shifting the guests $1/n$ over two rooms.
All the other real numbers in the interval stay fixed.
