Let $S = \lbrace 1, 2, 3, . . . , n\rbrace$ be a set. Consider a function $f : S \to S$. A subset $D$ of $S$ is said to be invariant if $\forall$ x $\in$ $D$ we have $f(x) \in D$. The empty set and $S$ are also considered as invariant subsets. By $\deg(f)$ we define the number of invariant subsets $D$ of $S$ for the function $f$.
The questions are--
Show that there exists a function $f : S \to S$ such that $\deg(f) = 2$.
Show that for every $1 \leq k \leq n$ there exists a function $f : S \to S$ such that $\deg(f) = 2^k$.
For the first case I tried to make guess a function such that $f(x)=x+1$ for all $x\in[1,n-1]$ and $f(n)=1$. Clearly the set $S$ satisfies the condition.But I could not find out another set which satisfies this function. Any help is appreciated. Thanks.