TITLE: How many times does $k$ occur in the composition of $n$?
QUESTION [6 upvotes]: How many times does the number $k$ occur in the composition of $n$?
Composition of Integer 
In short, the difference between the partition of an integer and composition is the order of numbers. In partition, the order doesn't matter whereas, in composition, it does. That's why Partitions are sometimes called as ordered Compositions.
Example: $k$ = $1$ & $n$ = $5$
The composition of 5 are:
$5$ 
$4 + 1$
$3 + 2$
$3 + 1 + 1$
$2 + 3$
$2 + 2 + 1$
$2 + 1 + 2$
$2 + 1 + 1 + 1$
$1 + 4$
$1 + 3 + 1$
$1 + 2 + 2$
$1 + 2 + 1 + 1$
$1 + 1 + 3$
$1 + 1 + 2 + 1$
$1 + 1 + 1 + 2$
$1 + 1 + 1 + 1 + 1$
In all $1$ occurs $28$ times in the composition of $5$
Similarly is there any relation between $k$ and $n$ for all $n \geq 0$ & $k \leq n$

REPLY [3 votes]: Suppose that $k$ (such that $0<k<n$) occurs at "position $p$" in a composition of $n$: $$\ldots+k+\ldots$$
by which I mean that everything to its left is a composition of $p$, and everything to its right is a composition of $n-p-k$.
If $p>0$ and $n-p-k>0$, there are $2^{p-1}$ compositions of $p$ and $2^{n-p-k-1}$ compositions of $n-p-k$, thus there are $2^{p-1}\cdot2^{n-p-k-1}=2^{n-k-2}$ possibilities for the rest of the composition of $n$. If $p=0$ or $n-p-k=0$, there are $2^{n-k-1}$ possibilities for the rest of the composition of $n$.
Summing over $p$, you will find that for $k<n$ the answer is: $$2\cdot2^{n-k-1}+\sum_{p=1}^{n-k-1}2^{n-k-2}=(n-k+3)\cdot2^{n-k-2}$$