1

Let $S$ be the set of all strings of $0$'s and $1$'s, and define $D:S \rightarrow \mathbb{Z}$ as follows: For all $s\in S$, $D(s)= \text{the number of}\,\, 1$'s in $s$ minus the number of $0$'s in $s$.

a. Is $D$ one-to-one(injective)? Prove or give counterexample if it is false. b. Is $D$ onto(surjective)? Prove or give a counterexample.

a. I know $D(S1)\neq D(S2)$ and $S1=S2$. Since $11000\neq 10100$ but $D(11000)=-1$ and $D(10100)=-1$. So does that means that D is not one-to-one?

b. ?

J126
  • 17,451
Fred
  • 171

2 Answers2

2

You need to determine if you can get any integer. You have shown something maps to $-1$. Given an integer $n>0$, can you find a string that has $n$ more $1$'s than $0$'s? Given $n<0$, can you find a string that has $n$ more $0$'s than $1$'s? What about $n=0$?

J126
  • 17,451
2

a) Yes, the function is indeed not injective, and your idea is correct!
b) You have to show that, given an arbitrary integer $n$, then you can find a string $S$ such that $D(S)=n$. For example, if $n=3$, then take $S=111$...

sranthrop
  • 8,497