Binary expansion and correspondence of finite strings

129 Views Asked by At

How can we show that there is a one-to one correspondence between finite strings of the symbols 1 and 0 and the naturals $\mathbb{N}$. I was thinking along the lines of maybe using a 2-tuple, but couldnt get far.

3

There are 3 best solutions below

2
On BEST ANSWER

Represent each finite string as an ordered pair in the following way: the first element of the pair is the interpretation of the string as a natural number, and the second is the number of leading zeroes. Now use any bijection between $\Bbb N\times\Bbb N$ and $\Bbb N$.

0
On

Pick $n \in \mathbb{N}$. There will be $k \in \mathbb{N}_0$ such that $2^k \le n < 2^{k + 1}$. Now consider $n - 2^k$, rinse and repeat.

0
On

A poem for you, dear OP:

Order the strings by length ascendingly,

and among strings of the same length lexicographically.

"$n$-th in this order" matches strings to natural numbers bijectively.

Prove it carefully.